Advertisement
Dmaxiya

奇怪的数 参考代码

Apr 8th, 2025
453
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.79 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long LL;
  5. const LL MOD = 998244353;
  6. const int maxn = 10;
  7. int n, m;
  8. LL ans;
  9. LL dp[2][maxn][maxn][maxn][maxn];
  10.  
  11. int main() {
  12. #ifdef ExRoc
  13.     freopen("test.txt", "r", stdin);
  14. #endif  // ExRoc
  15.     ios::sync_with_stdio(false);
  16.  
  17.     cin >> n >> m;
  18.     for (int a = 1; a < 10; a += 2) {
  19.         for (int b = 0; b < 10; b += 2) {
  20.             for (int c = 1; c < 10; c += 2) {
  21.                 for (int d = 0; d < 10; d += 2) {
  22.                     if (a + b + c + d <= m) {
  23.                         dp[0][a][b][c][d] = 1;
  24.                     }
  25.                 }
  26.             }
  27.         }
  28.     }
  29.  
  30.     for (int i = 5; i <= n; ++i) {
  31.         int nowi = (i % 2);
  32.         int prei = nowi ^ 1;
  33.         memset(dp[nowi], 0, sizeof(dp[nowi]));
  34.         for (int e = nowi; e < 10; e += 2) {
  35.             for (int d = nowi ^ 1; d < 10; d += 2) {
  36.                 for (int c = nowi; c < 10; c += 2) {
  37.                     for (int b = nowi ^ 1; b < 10; b += 2) {
  38.                         for (int a = nowi; a < 10; a += 2) {
  39.                             if (a + b + c + d + e > m) {
  40.                                 continue;
  41.                             }
  42.                             dp[nowi][b][c][d][e] =
  43.                                 (dp[nowi][b][c][d][e] + dp[prei][a][b][c][d]) %
  44.                                 MOD;
  45.                         }
  46.                     }
  47.                 }
  48.             }
  49.         }
  50.     }
  51.  
  52.     for (int a = 0; a < 10; ++a) {
  53.         for (int b = 0; b < 10; ++b) {
  54.             for (int c = 0; c < 10; ++c) {
  55.                 for (int d = 0; d < 10; ++d) {
  56.                     ans = (ans + dp[n & 1][a][b][c][d]) % MOD;
  57.                 }
  58.             }
  59.         }
  60.     }
  61.     cout << ans << endl;
  62.  
  63.     return 0;
  64. }
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement