Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d548048

Browse files
committed
고다혜: [BOJ] 14852 타일 채우기 3_250326
1 parent cd370fe commit d548048

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

‎BOJ/10001-15000번/DH_14852.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import java.io.*;
2+
3+
/*
4+
* 타일 채우기 3
5+
*/
6+
7+
public class DH_14852 {
8+
static final int MOD = 1_000_000_007;
9+
10+
public static void main(String[] args) throws Exception {
11+
12+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
13+
int N = Integer.parseInt(br.readLine());
14+
15+
long[] dp = new long[Math.max(4, N + 1)];
16+
17+
dp[1] = 2;
18+
dp[2] = 7;
19+
20+
long sum = 2; // 기본으로 더해지는거
21+
22+
for(int i = 3; i < dp.length; i++) {
23+
// sum 에는 dp[i - 3] * 2 + dp[i - 4] * 2 + dp[i - 5] * 2 ...가 저장되어 있음
24+
long tmp = dp[i - 1] * 2 + dp[i - 2] * 3 + sum;
25+
dp[i] = tmp % MOD;
26+
sum += dp[i - 2] * 2;
27+
}
28+
29+
System.out.println(dp[N] % MOD);
30+
}
31+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /