Advertisement
STANAANDREY

tpa lab10 prop O(n)

May 4th, 2023 (edited)
946
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const string FNAME = "data";
  4. ifstream fin(FNAME + ".in");
  5. ofstream fout(FNAME + ".out");
  6. constexpr int MOD = 1'000'000'007;//'
  7.  
  8. int main() {
  9.     int n;
  10.     fin >> n;
  11.     int dp[3] = {1, 3};
  12.     for (int i = 3; i <= n; i++) {
  13.         dp[2] = (2LL * dp[0] % MOD + dp[1]) % MOD;
  14.         dp[0] = dp[1];
  15.         dp[1] = dp[2];
  16.     }
  17.     fout << dp[2] << endl;
  18.     fout.close();
  19.     return 0;
  20. }
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement