forked from 2ByungJun/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path7.java
More file actions
24 lines (18 loc) ยท 618 Bytes
/
7.java
File metadata and controls
24 lines (18 loc) ยท 618 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import java.util.*;
public class Main {
// ์์ ๊ณ์ฐ๋ ๊ฒฐ๊ณผ๋ฅผ ์ ์ฅํ๊ธฐ ์ํ DP ํ
์ด๋ธ ์ด๊ธฐํ
public static int[] d = new int[1001];
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// ์ ์ N์ ์
๋ ฅ๋ฐ๊ธฐ
int n = sc.nextInt();
// ๋ค์ด๋๋ฏน ํ๋ก๊ทธ๋๋ฐ(Dynamic Programming) ์งํ(๋ณดํ
์
)
d[1] = 1;
d[2] = 3;
for (int i = 3; i <= n; i++) {
d[i] = (d[i - 1] + 2 * d[i - 2]) % 796796;
}
// ๊ณ์ฐ๋ ๊ฒฐ๊ณผ ์ถ๋ ฅ
System.out.println(d[n]);
}
}