Raslboyy

75B

Oct 3rd, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. typedef long long ll;
  8.  
  9. bool bit(ll var, int pos) {
  10.     return ((var >> pos) & 1);
  11. }
  12.  
  13. int main() {
  14.     ifstream fin("input.txt");
  15.     ofstream fout("output.txt");
  16.  
  17.     int n, m;
  18.     fin >> n >> m;
  19.     vector<vector<vector<ll>>> dp(n + 1, vector<vector<ll>>(m + 1, vector<ll>(1 << n + 1)));
  20.     for (int j = 0; j < m; j++) {
  21.         for (int i = 0; i < (1 << n + 1); i++) dp[j][0][i] = 1;
  22.     }
  23.     for (int i = 0; i < (1 << 1); i++) dp[0][1][i] = 1;
  24.     for (int j = 0; j < m; j++) {
  25.         for (int i = 0; i < n; i++) {
  26.             for (int prof = 0; prof < (1 << n + 1); prof++) {
  27.                 if (i == n - 1) {
  28.                     dp[0][j + 1][((prof << 1) & ~(1 << n+1))] += dp[i][j][prof];
  29.                     dp[0][j + 1][((prof << 1) & ~(1 << n + 1)) | 1] += dp[i][j][prof];
  30.                 }
  31.                 else {
  32.                     int sum = bit(prof, i - 1) + bit(prof, i) + bit(prof, i + 1);
  33.                     if (sum + 1 != 4) dp[i + 1][j][(prof | (1 << i))] += dp[i][j][prof];
  34.                     if (sum != 0) dp[i + 1][j][(prof & (~(1 << i)))] += dp[i][j][prof];
  35.                 }
  36.             }
  37.         }
  38.     }
  39.    
  40.  
  41.     fin.close();
  42.     fout.close();
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment