From 07aee8ba8129af1310b9e4fd08834214439f940c Mon Sep 17 00:00:00 2001 From: Ritik2604 <49342895+Ritik2604@users.noreply.github.com> Date: Sat, 23 May 2020 05:34:56 +0530 Subject: [PATCH] Create BoardPath --- DynamicProgramming/BoardPath | 52 ++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 DynamicProgramming/BoardPath diff --git a/DynamicProgramming/BoardPath b/DynamicProgramming/BoardPath new file mode 100644 index 00000000..4b471a88 --- /dev/null +++ b/DynamicProgramming/BoardPath @@ -0,0 +1,52 @@ + +public class BoardPath { + public static long startTime; + public static long endTime; + public static void startAlgo() { + startTime=System.currentTimeMillis(); + } + public static long endAlgo() { + endTime=System.currentTimeMillis(); + return endTime-startTime; + } + public static int bpR(int start,int end){ + if(start==end) { + return 1; + } + else if(start>end) + return 0; + int count=0; + for(int dice=1;dice<=6;dice++) { + count+=bpR(start+dice,end); + } + return count; + } + public static int bpRS(int curr,int end,int strg[]){ + if(curr==end) { + return 1; + } + else if(curr>end) + return 0; + if(strg[curr]!=0) + return strg[curr]; + int count=0; + for(int dice=1;dice<=6;dice++) { + count+=bpRS(curr+dice,end,strg); + } + strg[curr]=count; + return count; + } + public static int bpIS(int curr,int end,int[]strg){ + strg[end]=1; + for(int i=end-1;i>=0;i--) { + int count=0; + for(int dice=1;dice<=6&&dice+i