@@ -0,0 +1,1186 @@
+package CrackingCoding;%0D%0A%0D%0Apublic class c9_1 %7B%0D%0A    public static int countWaysDP(int n, int%5B%5D map) %7B%0D%0A%09if (n %3C 0) %7B%0D%0A%09    return 0;%0D%0A%09%7D else if (n == 0) %7B%0D%0A%09    return 1;%0D%0A%09%7D else if (map%5Bn%5D %3E -1) %7B%0D%0A%09    return map%5Bn%5D;%0D%0A%09%7D else %7B%0D%0A%09    map%5Bn%5D = countWaysDP(n - 1, map) + countWaysDP(n - 2, map)%0D%0A%09%09    + countWaysDP(n - 3, map);%0D%0A%09    return map%5Bn%5D;%0D%0A%09%7D%0D%0A    %7D%0D%0A%0D%0A    public static int countWaysRecursive(int n) %7B%0D%0A%09if (n %3C 0) %7B%0D%0A%09    return 0;%0D%0A%09%7D else if (n == 0) %7B%0D%0A%09    return 1;%0D%0A%09%7D else %7B%0D%0A%09    return countWaysRecursive(n - 1) + countWaysRecursive(n - 2)%0D%0A%09%09    + countWaysRecursive(n - 3);%0D%0A%09%7D%0D%0A    %7D%0D%0A%0D%0A    public static void main(String%5B%5D args) %7B%0D%0A%09for (int i = 0; i %3C 30; i++) %7B%0D%0A%09    long t1 = System.currentTimeMillis();%0D%0A%09    int%5B%5D map = new int%5B30 + 1%5D;%0D%0A%09    for (int j = 0; j %3C map.length; j++) %7B%0D%0A%09%09map%5Bj%5D = -1;%0D%0A%09    %7D%0D%0A%09    int c1 = countWaysDP(i, map);%0D%0A%09    long t2 = System.currentTimeMillis();%0D%0A%09    long d1 = t2 - t1;%0D%0A%0D%0A%09    long t3 = System.currentTimeMillis();%0D%0A%09    int c2 = countWaysRecursive(i);%0D%0A%09    long t4 = System.currentTimeMillis();%0D%0A%09    long d2 = t4 - t3;%0D%0A%09    System.out.println(i + %22 %22 + c1 + %22 %22 + c2 + %22 %22 + d1 + %22 %22 + d2);%0D%0A%09%7D%0D%0A    %7D%0D%0A%7D%0D%0A

add a question