Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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