Advertisement
Dmaxiya

哇,这就是 5p 参考代码

Mar 30th, 2025
624
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long LL;
  5. const int maxn = 100000 + 100;
  6. const int maxm = 1000 + 100;
  7. const LL MOD = 998244853;
  8. int n, m;
  9. LL a[maxn], p[maxn], dp[2][maxm];
  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 i = 1; i <= n; ++i) {
  19.         cin >> a[i];
  20.         a[i] %= m;
  21.     }
  22.     for (int i = 1; i <= n; ++i) {
  23.         cin >> p[i];
  24.         p[i] %= MOD;
  25.     }
  26.     dp[0][0] = 1;
  27.     for (int i = 1; i <= n; ++i) {
  28.         int nowi = i % 2;
  29.         int prei = nowi ^ 1;
  30.         for (int j = 0; j < m; ++j) {
  31.             dp[nowi][j] = (dp[prei][j] * ((((1 - p[i]) % MOD) + MOD) % MOD) % MOD + dp[prei][(j - a[i] + m) % m] * p[i] % MOD) % MOD;
  32.         }
  33.     }
  34.     cout << dp[n & 1][0] << endl;
  35.  
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement