-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStairs1017.java
54 lines (38 loc) · 1.09 KB
/
Stairs1017.java
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
45
46
47
48
49
50
51
52
53
import java.io.*;
import java.util.*;
public class Stairs1017
{
public static long cache[][];
public static long cnt(int total, int prevLength)
{
if (total == 0) {
return 1L;
}
long count = 0;
for (int i = prevLength+1; i <= total; i++) {
count += stairsCount( total - i, i);
}
return count;
}
public static long stairsCount(int total, int minLength) {
if (cache[total][minLength] == 0L) {
cache[total][minLength] = cnt(total, minLength);
}
return cache[total][minLength];
}
public static void warn(String s) {
System.out.println(s);
}
public static void main(String[] argv) {
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n = in.nextInt();
cache = new long[n+1][n+1];
long count = 0;
for (int i = 1; i < n; i++) {
count += stairsCount(n - i, i);
}
out.println( "" + count );
out.flush();
}
}