Raslboyy

2998

Sep 3rd, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. typedef long long ll;
  9.  
  10. int main() {
  11.     ifstream fin("input.txt");
  12.     ofstream fout("output.txt");
  13.  
  14.     int n;
  15.     const int TEN = 10;
  16.     fin >> n;
  17.     vector<vector<ll>> dp(n + 1, vector<ll>(TEN));
  18.     dp[1][0] = 0;
  19.     for (int i = 1; i < TEN; i++) dp[1][i] = 1;
  20.     for (int i = 2; i <= n; i++) {
  21.         dp[i][0] = dp[i - 1][0] + dp[i - 1][1];
  22.         for (int j = 1; j < TEN - 1; j++)
  23.             dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1] + dp[i - 1][j + 1];
  24.         dp[i][9] = dp[i - 1][9] + dp[i - 1][8];
  25.     }
  26.     ll res = 0;
  27.     for (ll i : dp[n])
  28.         res += i;
  29.     fout << res << endl;
  30.  
  31.     fin.close();
  32.     fout.close();
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment