ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1017. Staircases

Right algo but too slow
Posted by Bekmuhamet 11 Sep 2020 13:23
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
Posted by Mariouz 9 Apr 2021 19:01
Use bottom-up approach, calling function and return rakes huge amount of time