Created
September 15, 2014 16:42
-
-
Save bitcpf/4e7da731142acd4ddd8d 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 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