-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTiling.java
More file actions
44 lines (32 loc) · 695 Bytes
/
Tiling.java
File metadata and controls
44 lines (32 loc) · 695 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
44
package dynamic;
import java.util.Scanner;
public class Tiling {
static int[] d;
public static void main(String[] args) {
// #11726¹ø_2xn ŸÀϸµ
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
d = new int[n+1];
System.out.println(topDown(n));
sc.close();
}
public static int topDown(int n) {
if(n==0|| n==1)
return 1;
if(d[n] > 0)
return d[n];
d[n] = topDown(n-2) + topDown(n-1);
d[n] %= 10007;
return d[n];
}
public static int bottomUp(int n) {
d[0] = 1;
if(n > 0)
d[1] = 1;
for(int i=2; i<=n; i++) {
d[i] = d[i-2] + d[i-1];
d[i] %= 10007;
}
return d[n];
}
}