fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. long long arr[61] = {0};
  5.  
  6. long long num_of_ways(int n){
  7. if(arr[n]) {
  8. return arr[n];
  9. }
  10. else {
  11. arr[n] = num_of_ways(n-1) + num_of_ways(n-2) + num_of_ways(n-3);
  12. }
  13. return arr[n];
  14. }
  15. int main() {
  16. int n;
  17. cin >> n;
  18. arr[0] = 1;
  19. arr[1] = 1;
  20. arr[2] = 2;
  21. cout << num_of_ways(n);
  22. return 0;
  23. }
Success #stdin #stdout 0s 4548KB
stdin
60
stdout
4680045560037375