Skip to content

Commit f87750d

Browse files
committed
issue #43 1904
1 parent 286f6bf commit f87750d

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/backjoon/_1904.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
*/

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy