Raslboyy

213

Sep 14th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 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<vector<int>> vec = { {4, 6}, {6, 8}, {7, 9}, {4, 8}, {0, 3, 9}, {}, {0, 1, 7}, {2, 6}, {1, 3}, {2, 4} };
  14.     vector<vector<int>> dp(n + 1, vector<int>(10));
  15.     for (int i = 0; i < 10; i++) dp[1][i] = 1;
  16.     for (int i = 2; i <= n; i++)
  17.         for (int j = 0; j < 10; j++)
  18.             for (int to : vec[j])
  19.                 dp[i][j] += dp[i - 1][to];
  20.     int sum = 0;
  21.     for (int i = 1; i < 10; i++) {
  22.         sum += dp[n][i] * int(i != 8);
  23.     }
  24.     fout << sum << endl;
  25.        
  26.     fin.close();
  27.     fout.close();
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment