File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change 1+ package backjoon ;
2+ // https://www.acmicpc.net/problem/1904
3+
4+ import java .io .BufferedReader ;
5+ import java .io .IOException ;
6+ import java .io .InputStreamReader ;
7+
8+ public class _1904 {
9+ // 첫 번째 줄에 자연수 N이 주어진다. (1 ≤ N ≤ 1,000,000)
10+ // memory 51820 runtime 264
11+ public static int [] dp = new int [1000001 ];
12+ public static void main (String [] args ) throws IOException {
13+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
14+ int N = Integer .parseInt (br .readLine ());
15+
16+ //피보나치 수열
17+ dp [0 ] = 0 ;
18+ dp [1 ] = 1 ;
19+ dp [2 ] = 2 ;
20+
21+ // -1로 초기화
22+ for (int i =3 ; i < dp .length ; i ++ ){
23+ dp [i ] = -1 ;
24+ }
25+
26+ System .out .println (Tile (N ));
27+ }
28+
29+ static int Tile (int n ){
30+ if (dp [n ] == -1 ){
31+ dp [n ] = (Tile (n -1 ) + Tile (n -2 )) % 15746 ;
32+ }
33+ return dp [n ];
34+ }
35+
36+ }
37+ /*
38+ input
39+ 4
40+
41+ output
42+ 5
43+ */
You can’t perform that action at this time.
0 commit comments