Skip to content

Instantly share code, notes, and snippets.

@thmain
Last active December 27, 2020 04:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thmain/b9e53572f638552336b6 to your computer and use it in GitHub Desktop.
Save thmain/b9e53572f638552336b6 to your computer and use it in GitHub Desktop.
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