From 1dcde562afb9a58b0510b4e5afecc50dad5a740d Mon Sep 17 00:00:00 2001 From: Jinyeong Seol Date: Sun, 23 Feb 2025 21:41:58 +0900 Subject: [PATCH] =?UTF-8?q?[20250223]=20BOJ=20/=20=EA=B3=A8=EB=93=9C4=20/?= =?UTF-8?q?=20=ED=83=80=EC=9D=BC=20=EC=B1=84=EC=9A=B0=EA=B8=B0=203=20/=20?= =?UTF-8?q?=EC=84=A4=EC=A7=84=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\261\204\354\232\260\352\270\260 3.md" | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 "Seol-JY/202502/23 BOJ G4 \355\203\200\354\235\274 \354\261\204\354\232\260\352\270\260 3.md" diff --git "a/Seol-JY/202502/23 BOJ G4 \355\203\200\354\235\274 \354\261\204\354\232\260\352\270\260 3.md" "b/Seol-JY/202502/23 BOJ G4 \355\203\200\354\235\274 \354\261\204\354\232\260\352\270\260 3.md" new file mode 100644 index 00000000..6eba96b5 --- /dev/null +++ "b/Seol-JY/202502/23 BOJ G4 \355\203\200\354\235\274 \354\261\204\354\232\260\352\270\260 3.md" @@ -0,0 +1,24 @@ +```java +import java.io.*; +public class Main { + static int N; + static final int MOD = 1000000007; + static long[][] dp = new long[1000001][2]; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + N = Integer.parseInt(br.readLine()); + dp[0][0] = 0; + dp[1][0] = 2; + dp[2][0] = 7; + dp[2][1] = 1; + + for (int i = 3; i <= N; i++) { + dp[i][1] = (dp[i - 3][0] + dp[i - 1][1]) % MOD; // i - 3 까지 누적합 + 1 + dp[i][0] = (3 * (dp[i - 2][0]) + 2 * (dp[i - 1][0]) + 2 * dp[i][1]) % MOD; + } + + System.out.println(dp[N][0]); + } +} +```