(int n, int[] map)
| 3 | public class Question { |
| 4 | |
| 5 | public static int countWaysDP(int n, int[] map) { |
| 6 | if (n < 0) { |
| 7 | return 0; |
| 8 | } else if (n == 0) { |
| 9 | return 1; |
| 10 | } else if (map[n] > -1) { |
| 11 | return map[n]; |
| 12 | } else { |
| 13 | map[n] = countWaysDP(n - 1, map) + |
| 14 | countWaysDP(n - 2, map) + |
| 15 | countWaysDP(n - 3, map); |
| 16 | return map[n]; |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | public static int countWaysRecursive(int n) { |
| 21 | if (n < 0) { |