Raslboyy

912

Sep 19th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     ifstream fin("input.txt");
  9.     ofstream fout("output.txt");
  10.  
  11.     int n;
  12.     fin >> n;
  13.     vector<int> dp(n + 3);
  14.     dp[1] = 2;
  15.     dp[2] = 4;
  16.     dp[3] = 7;
  17.     for (int i = 4; i <= n; i++)
  18.         dp[i] = dp[i - 1] + dp[i - 2] + dp[i - 3];
  19.     fout << dp[n] << endl;
  20.  
  21.  
  22.     fin.close();
  23.     fout.close();
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment