Advertisement
AlejandroGY

Untitled

Feb 9th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. #include <cstdio>
  2.  
  3. int n;
  4.  
  5. int solve(int num)
  6. {
  7.    if (num == 0) {
  8.       return 1;
  9.    } else if (num == 1) {
  10.       return 2;
  11.    } else if (num == 2) {
  12.       return 4;
  13.    } else if (num == 3) {
  14.       return 7;
  15.    } else {
  16.       int res = 0;
  17.       res += solve(num - 1) + solve(num - 2) + solve(num - 3);
  18.       return res;
  19.    }
  20. }
  21.  
  22. int main( )
  23. {
  24.     int n;
  25.    std::scanf("%d", &n);
  26.    std::printf("%d", solve(n));
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement