Skip to content

Commit 07aee8b

Browse files
authored
Create BoardPath
1 parent ef2be07 commit 07aee8b

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

DynamicProgramming/BoardPath

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
2+
public class BoardPath {
3+
public static long startTime;
4+
public static long endTime;
5+
public static void startAlgo() {
6+
startTime=System.currentTimeMillis();
7+
}
8+
public static long endAlgo() {
9+
endTime=System.currentTimeMillis();
10+
return endTime-startTime;
11+
}
12+
public static int bpR(int start,int end){
13+
if(start==end) {
14+
return 1;
15+
}
16+
else if(start>end)
17+
return 0;
18+
int count=0;
19+
for(int dice=1;dice<=6;dice++) {
20+
count+=bpR(start+dice,end);
21+
}
22+
return count;
23+
}
24+
public static int bpRS(int curr,int end,int strg[]){
25+
if(curr==end) {
26+
return 1;
27+
}
28+
else if(curr>end)
29+
return 0;
30+
if(strg[curr]!=0)
31+
return strg[curr];
32+
int count=0;
33+
for(int dice=1;dice<=6;dice++) {
34+
count+=bpRS(curr+dice,end,strg);
35+
}
36+
strg[curr]=count;
37+
return count;
38+
}
39+
public static int bpIS(int curr,int end,int[]strg){
40+
strg[end]=1;
41+
for(int i=end-1;i>=0;i--) {
42+
int count=0;
43+
for(int dice=1;dice<=6&&dice+i<strg.length;dice++) {
44+
count+=strg[i+dice];
45+
}
46+
strg[i]=count;
47+
}
48+
return strg[0];
49+
}
50+
51+
52+
}

0 commit comments

Comments
 (0)