-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem15.java
More file actions
50 lines (32 loc) · 761 Bytes
/
Problem15.java
File metadata and controls
50 lines (32 loc) · 761 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
45
46
47
48
49
public class Problem15 {
public static void main(String[] args){
System.out.println("Count: " + iterCount(20));
}
public static long pathCount(int row, int col){
if((row == 19) && (col == 19))
return 1;
if((row < 20) && (col < 20))
return pathCount(row+1, col) + pathCount(row, col+1);
if(row < 20)
return 1 + pathCount(row+1, col);
if(col < 20)
return 1 + pathCount(row, col+1);
return 0;
}
public static long iterCount(int sizeOf){
long[] l = new long[sizeOf+1];
for( int i = 0; i <= sizeOf ; i++)
l[i] = 1L;
int i = 1;
while( i <= sizeOf ){
int j = 1;
while( j < i){
l[j] = l[j] + l[j-1];
j++;
}
l[i] = 2L * l[i-1];
i++;
}
return l[sizeOf];
}
}