-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboardPathDP.java
More file actions
39 lines (32 loc) · 1.07 KB
/
boardPathDP.java
File metadata and controls
39 lines (32 loc) · 1.07 KB
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
import java.util.*;
class main{
public static int solve(int x,int y,int xf,int yf){
if(x==xf && y==yf) return 1;
if(x>xf || y>yf) return 0;
int count=0;
count+=solve(x+1,y,xf,yf)+solve(x, y+1, xf, yf);
return count;
}
public static long solvePath(int x , int y , int xf , int yf , long dp[][]){
if(x==xf && y==yf) return 1;
if(x>xf || y>yf) return 0;
if(dp[y][x]!=0) return dp[y][x];
long count=0;
count+=solvePath(x+1, y, xf, yf, dp)+solvePath(x, y+1, xf, yf, dp);
dp[y][x]=count;
return count;
}
static int solvePathTB(int x , int y , int tb[][]){
return 1;
}
public static void main(String[] args) {
int x=17;;
int y=17;
long t1=System.currentTimeMillis();
long dp[][] = new long[x+1][y+1];
// System.out.println(solve(0, 0, x, y));
System.out.println(solvePath(0, 0, x, y, dp));
long time = System.currentTimeMillis()-t1;
System.out.println(time);
}
}