Skip to content

Instantly share code, notes, and snippets.

@bitcpf
Created September 15, 2014 16:42
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 bitcpf/4e7da731142acd4ddd8d to your computer and use it in GitHub Desktop.
Save bitcpf/4e7da731142acd4ddd8d to your computer and use it in GitHub Desktop.
public class Q9_1 {
public static void main(String[] args){
int test = 10;
System.out.println("Total Stair No.: "+test);
int[] maptest = new int [test];
for (int i=0;i < maptest.length;i++){
maptest[i] = -1;
}
System.out.println("Result.: "+ countWays(test,maptest));
}
public static int countWays(int n, int[] map){
//System.out.println(n);
if (n < 0){
return 0;
}
else if (n == 0)
return 1;
// else{
// return countWays(n-1)+countWays(n-2)+countWays(n-3);
// }
else if(map[n-1] >= 0){
return map[n-1];
}
else{
map[n-1] = countWays(n-1, map)+countWays(n-2,map)+countWays(n-3,map);
return map[n-1];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment