Dmaxiya

[蓝桥杯 2026 省 A] 量子 2048 参考代码

Apr 12th, 2026
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.21 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define endl '\n'
  5. typedef long long LL;
  6.  
  7. bool canPutZero(int x, int y, int n, vector<int>& row, vector<int>& col,
  8.                 vector<vector<int>>& v) {
  9.     if (x == n - 1) {
  10.         if (col[y] == 0) {
  11.             return false;
  12.         }
  13.     }
  14.     if (y == n - 1) {
  15.         if (row[x] == 0) {
  16.             return false;
  17.         }
  18.     }
  19.     if (x != 0 && y != 0) {
  20.         if ((v[x - 1][y - 1] + v[x - 1][y] + v[x][y - 1]) % 2 == 0) {
  21.             return false;
  22.         }
  23.     }
  24.     return true;
  25. }
  26.  
  27. bool canPutOne(int x, int y, int n, vector<int>& row, vector<int>& col,
  28.                vector<vector<int>>& v) {
  29.     if (x == n - 1) {
  30.         if (col[y] == 1) {
  31.             return false;
  32.         }
  33.     }
  34.     if (y == n - 1) {
  35.         if (row[x] == 1) {
  36.             return false;
  37.         }
  38.     }
  39.     if (x != 0 && y != 0) {
  40.         if ((v[x - 1][y - 1] + v[x - 1][y] + v[x][y - 1]) % 2 == 1) {
  41.             return false;
  42.         }
  43.     }
  44.     return true;
  45. }
  46.  
  47. void dfs(int depth, int n, int& ans, vector<int>& row, vector<int>& col,
  48.          vector<vector<int>>& v) {
  49.     if (depth == n * n) {
  50.         ++ans;
  51.         return;
  52.     }
  53.     int x = depth / n;
  54.     int y = depth % n;
  55.     if (canPutZero(x, y, n, row, col, v)) {
  56.         dfs(depth + 1, n, ans, row, col, v);
  57.     }
  58.     if (canPutOne(x, y, n, row, col, v)) {
  59.         row[x] ^= 1;
  60.         col[y] ^= 1;
  61.         v[x][y] = 1;
  62.         dfs(depth + 1, n, ans, row, col, v);
  63.         row[x] ^= 1;
  64.         col[y] ^= 1;
  65.         v[x][y] = 0;
  66.     }
  67. }
  68.  
  69. // void solve(int n) {
  70. //     vector<vector<int>> v(n, vector<int>(n, 0));
  71. //     vector<int> row(n, 0), col(n, 0);
  72. //     int ans = 0;
  73. //     dfs(0, n, ans, row, col, v);
  74. //     cout << "n = " << n << " ans = " << ans << endl;
  75. // }
  76.  
  77. LL fastPow(LL res, LL n, LL MOD) {
  78.     LL ans;
  79.     for (ans = 1; n != 0; n >>= 1) {
  80.         if ((n & 1) == 1) {
  81.             ans = ans * res % MOD;
  82.         }
  83.         res = res * res % MOD;
  84.     }
  85.     return ans;
  86. }
  87.  
  88. int main() {
  89.     ios::sync_with_stdio(false);
  90.  
  91.     // for (int n = 2; n < 15; n++) {
  92.     //     solve(n);
  93.     // }
  94.     cout << fastPow(2, 511 * 8 + 5, 998244353) << endl;
  95.  
  96.     return 0;
  97. }
  98.  
Advertisement
Add Comment
Please, Sign In to add comment