Last active
December 27, 2020 04:19
-
-
Save thmain/b9e53572f638552336b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class StepsPossiblePathsRecur { | |
public int possibleWaysDyna(int n, int[] dyn) { | |
if (n == 0) | |
return 1; | |
if (n < 0) | |
return 0; | |
if (dyn[n] > 0) { | |
return dyn[n]; | |
} | |
dyn[n] = possibleWaysDyna(n - 1, dyn) + possibleWaysDyna(n - 2, dyn) | |
+ possibleWaysDyna(n - 3, dyn); | |
return dyn[n]; | |
} | |
public static void main(String[] args) { | |
// TODO Auto-generated method stub | |
int n = 3; | |
StepsPossiblePathsRecur s = new StepsPossiblePathsRecur(); | |
int[] dyn = new int[n + 1]; | |
System.out.println(s.possibleWaysDyna(n, dyn)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment