Advertisement
reverser1

Untitled

Jun 9th, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.47 KB | None | 0 0
  1. #pragma GCC optimize("O3", "unroll-loops")
  2.  
  3. #include <bits/stdc++.h>
  4.  
  5. using namespace std;
  6.  
  7. const int inf = 1 << 30;
  8. const long long MOD = 1e9 + 7;
  9.  
  10. typedef long long ll;
  11. typedef long double ld;
  12. typedef vector<int> vi;
  13. typedef pair<int, int> ii;
  14. typedef vector<ii> vii;
  15. typedef vector<vi> vvi;
  16. typedef vector<bool> vb;
  17.  
  18. #define FAST ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  19. #define all(a) a.begin(), a.end()
  20. #define pb push_back
  21. #define files(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)
  22. #define ppb pop_back
  23. #define ppf pop_front
  24. #define fs first
  25. #define sd second
  26. #define eb emplace_back
  27.  
  28. template<class T> inline void sort(T &a) { sort(all(a)); }
  29. template<class T> inline T sorted(T a) { sort(a); return a; }
  30. template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }
  31.  
  32. void solve() {
  33.     int n;
  34.     cin >> n;
  35.     vector<ll> dp(n);
  36.     if (n == 1) {
  37.         cout << 1;
  38.         return;
  39.     } else if (n == 2) {
  40.         cout << 2;
  41.         return;
  42.     } else if (n == 3) {
  43.         cout << 4;
  44.         return;
  45.     }
  46.     dp[n - 1] = 1;
  47.     dp[n - 2] = 2;
  48.     dp[n - 3] = 4;
  49.     for (int i = n - 4; i >= 0; --i) {
  50.         dp[i] = dp[i + 1] + dp[i + 2] + dp[i + 3];
  51.     }
  52.     cout << dp[0];
  53. }
  54.  
  55. signed main() {
  56.     FAST;
  57.     // files("input.in", "output.out");
  58.     int q = 1;
  59.     // cin >> q;
  60.     while (q--) {
  61.         solve();
  62.     }
  63.     return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement