forked from ndb796/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]);
}
}