fork download
  1. public class Main{
  2. public static long array[] = new long[61];
  3. public static long num_of_ways(int n){
  4. if(array[n] == 0) {
  5. array[n] = num_of_ways(n-1) + num_of_ways(n-2) + num_of_ways(n-3);
  6. return array[n];
  7. }
  8. else {
  9. return array[n];
  10. }
  11. }
  12. public static void main (String[] args) throws java.lang.Exception {
  13. java.util.Scanner i = new java.util.Scanner(System.in);
  14. int n = i.nextInt();
  15. array[0] = 1;
  16. array[1] = 1;
  17. array[2] = 2;
  18. System.out.print(num_of_ways(n));
  19. }
  20. }
Success #stdin #stdout 0.15s 35272KB
stdin
60
stdout
4680045560037375