Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- typedef long long ll;
- int main() {
- ifstream fin("input.txt");
- ofstream fout("output.txt");
- int n;
- const int TEN = 10;
- fin >> n;
- vector<vector<ll>> dp(n + 1, vector<ll>(TEN));
- dp[1][0] = 0;
- for (int i = 1; i < TEN; i++) dp[1][i] = 1;
- for (int i = 2; i <= n; i++) {
- dp[i][0] = dp[i - 1][0] + dp[i - 1][1];
- for (int j = 1; j < TEN - 1; j++)
- dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1] + dp[i - 1][j + 1];
- dp[i][9] = dp[i - 1][9] + dp[i - 1][8];
- }
- ll res = 0;
- for (ll i : dp[n])
- res += i;
- fout << res << endl;
- fin.close();
- fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment