A child is running up a staircase with n steps, and can hop either 1 step, 2 steps, 3 steps at a time. count how many possible ways the child can run up the stairs.
Class upstaircase {static void main (string [] ARGs) {/* enter your code here. read input from stdin. print Output to stdout * // string line1 = system. console. readline (). trim (); system. console. writeline (upstaircase. countwaysdp (2, new int [1, 100]); system. console. writeline (upstaircase. countwaysdp (3, new int [1, 100]); system. console. writeline (upstaircase. countwaysdp (4, new int [1, 100]); system. console. writeline (upstaircase. countwaysdp (5, new int [1, 100]); system. console. writeline (upstaircase. countwaysdp (36, new int [1, 100]); system. console. writeline (upstaircase. countwaysdp (38, new int [1, 100]); console. read ();} // o (3 ^ N ). exponential public static int countways (int n) {If (n <0) {return 0;} else if (n = 0) {return 1 ;} else {return countways (n-1) + countways (n-2) + countways (n-3); }}// DP: Dynamic programing. up to 37 will overflowed. using Long type is just delay but not resolve it. public static int countwaysdp (int n, int [] map) {If (n <0) {return 0;} else if (n = 0) {return 1 ;} else if (Map [N]> 0) {return map [N];} else {map [N] = countwaysdp (n-1, MAP) + countwaysdp (n-2, map) + countwaysdp (n-3, MAP); Return map [N] ;}}