From bf0c3c4e4235a8fdda205f5a30e00e91dcf63001 Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Tue, 18 Feb 2025 16:14:55 +0900 Subject: [PATCH] =?UTF-8?q?[20250218]=20BOJ=20/=20=EA=B3=A8=EB=93=9C3=20/?= =?UTF-8?q?=20=EA=B8=B0=EC=88=99=EC=82=AC=20=EC=9E=AC=EB=B0=B0=EC=A0=95=20?= =?UTF-8?q?/=20=EA=B9=80=EC=88=98=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4 \354\236\254\353\260\260\354\240\225.md" | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 "suyeun84/202502/18 BOJ G3 \352\270\260\354\210\231\354\202\254 \354\236\254\353\260\260\354\240\225.md" diff --git "a/suyeun84/202502/18 BOJ G3 \352\270\260\354\210\231\354\202\254 \354\236\254\353\260\260\354\240\225.md" "b/suyeun84/202502/18 BOJ G3 \352\270\260\354\210\231\354\202\254 \354\236\254\353\260\260\354\240\225.md" new file mode 100644 index 00000000..99c8942a --- /dev/null +++ "b/suyeun84/202502/18 BOJ G3 \352\270\260\354\210\231\354\202\254 \354\236\254\353\260\260\354\240\225.md" @@ -0,0 +1,36 @@ +```java +import java.util.*; +import java.io.*; + +public class Solution { + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + int T = Integer.parseInt(st.nextToken()); + int[] N = new int[T]; + int maxN = 0; + for (int tc = 0; tc < T; tc++) { + st = new StringTokenizer(br.readLine()); + N[tc] = Integer.parseInt(st.nextToken()); + maxN = Math.max(maxN, N[tc]); + } + long[] dp = new long[maxN+1]; + dp[2] = 1; + for (int i = 3; i <= maxN; i++) { + long total = 1; + long minus = 0; + long divide = 1; + for (int j = i; j > 2; j--) { + total *= j; + divide *= (i-j+1); + minus += total*dp[j-1]/divide; + } + dp[i] = total*2 - (minus+1); + } + for (int i = 0; i < T; i++) { + System.out.println(dp[N[i]]); + } + } +} +```