|
|
back to boardRight algo but too slow import java.util.Scanner; public class Staircases { public static void main(String... args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); System.out.println(find_Q(N, N)); }
static int find_Q(int X, int Y) { int U = X-1; if(Y<X) { U = Y; if(Y == 0 || Y ==1) return 1; } if(Y<=1) return 0; int A = 0; for(int i = U; i > 0; i--) A += find_Q(i, Y-i); return A; } } Re: Right algo but too slow Use bottom-up approach, calling function and return rakes huge amount of time |
|
|