forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 1
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]);
}
}