orazma

h.cpp

May 16th, 2026
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.78 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define f first
  3. #define s second
  4. #define pb push_back
  5. #define mp make_pair
  6. #define ll long long
  7.  
  8. #define IOS ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  9.  
  10. using namespace std;
  11. const int INF = 1e9 + 10;
  12. const int MOD = 1e9 + 7;
  13. const int MOD2 = 1e9 + 9;
  14. const int MAXN = 2e6 + 10;
  15. int a[MAXN];
  16. int dp[12][110][3000];
  17. int cnt[22][22];
  18. void solve(){
  19.     int n, m;
  20.     cin >> n >> m;
  21.     if (n > m)
  22.         swap(n, m);
  23.  
  24.     dp[0][1][0] = 1;
  25.     for (int j = 1; j <= m; j++){
  26.         for  (int i = 1; i <= n; i++){
  27.             for (int mask = 0; mask < (1 << n); mask++){
  28.                 if ((mask >> (i - 1)) & 1){
  29.                     dp[i][j][mask ^ (1 << (i - 1))] += dp[i - 1][j][mask];
  30.                     if (dp[i][j][mask ^ (1 << (i - 1))] >= MOD){
  31.                         dp[i][j][mask ^ (1 << (i - 1))] -= MOD;
  32.                     }
  33.                 }
  34.                 else{
  35.                     dp[i][j][mask ^ (1 << (i - 1))] += dp[i - 1][j][mask];
  36.                     if (dp[i][j][mask ^ (1 << (i - 1))] >= MOD){
  37.                         dp[i][j][mask ^ (1 << (i - 1))] -= MOD;
  38.                     }
  39.                     if (i < n && ((mask >> i) & 1) == 0){
  40.                         dp[i][j][mask ^ (1 << i)] += dp[i - 1][j][mask];
  41.                         if (dp[i][j][mask ^ (1 << i)] >= MOD){
  42.                             dp[i][j][mask ^ (1 << i)] -= MOD;
  43.                         }
  44.                     }
  45.                 }
  46.             }
  47.         }
  48.         for (int mask = 0; mask < (1 << n); mask++){
  49.             dp[0][j + 1][mask] = dp[n][j][mask];
  50.         }
  51.     }
  52.     cout << dp[n][m][0] << "\n";
  53.  
  54.  
  55.  
  56. }
  57.  
  58. int main() {
  59.     IOS;
  60.     int t = 1;
  61.     //cin >> t;
  62.     while(t--){
  63.         solve();
  64.     }
  65.     return 0;
  66. }
  67.  
Advertisement
Add Comment
Please, Sign In to add comment