-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path_1904.java
More file actions
43 lines (35 loc) · 857 Bytes
/
_1904.java
File metadata and controls
43 lines (35 loc) · 857 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package backjoon;
// https://www.acmicpc.net/problem/1904
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class _1904 {
// 첫 번째 줄에 자연수 N이 주어진다. (1 ≤ N ≤ 1,000,000)
// memory 51820 runtime 264
public static int[] dp = new int[1000001];
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
//피보나치 수열
dp[0] = 0;
dp[1] = 1;
dp[2] = 2;
// -1로 초기화
for(int i=3; i < dp.length; i++ ){
dp[i] = -1;
}
System.out.println(Tile(N));
}
static int Tile(int n){
if(dp[n] == -1){
dp[n] = (Tile(n-1) + Tile(n-2)) % 15746;
}
return dp[n];
}
}
/*
input
4
output
5
*/