学习博客:戳这里
附本人代码:
1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int maxn = 1e5 + 10; 5 const ll mod = 998244353; 6 set<int>nu[maxn], rol[2]; 7 int a[maxn]; 8 ll dp[maxn][222][3]; 9 int main() { 10 int n; 11 scanf("%d", &n); 12 for(int i = 1; i <= n; ++i) { 13 scanf("%lld", a+i); 14 } 15 //处理边界 16 if(a[1] == -1) { 17 for(int i = 1; i <= 200; ++i) { 18 dp[1][i][0] = 1ll; 19 } 20 } else { 21 dp[1][a[1]][0] = 1ll; 22 } 23 for(int i = 2; i <= n; ++i) { 24 ll sum = 0; 25 int len = 200; 26 if(a[i] != -1) len = a[i]; 27 for(int j = 1; j <= len; ++j) { // > 28 if(a[i] == -1 || j == a[i]) 29 dp[i][j][0] = (dp[i][j][0] + sum) % mod; 30 for(int k = 0; k < 3; ++k) { 31 sum = (sum + dp[i - 1][j][k]) % mod; 32 } 33 } 34 for(int j = 1; j <= len; ++j) { // == 35 for(int k = 0; k < 3; ++k) { 36 if(a[i] == -1 || j == a[i]) 37 dp[i][j][1] = (dp[i][j][1] + dp[i - 1][j][k]) % mod; 38 } 39 } 40 if(i == 2) continue; 41 len = 1; 42 if(a[i] != -1) len = a[i]; 43 sum = 0; 44 for(int j = 200; j >= len; --j) { // < 45 if(a[i] == -1 || j == a[i]) 46 dp[i][j][2] =(dp[i][j][2] + sum) % mod; 47 for(int k = 1; k < 3; ++k) { 48 sum = (sum + dp[i - 1][j][k]) % mod; 49 } 50 } 51 } 52 ll ans = 0; 53 for(int j = 1; j <= 200; ++j) { 54 for(int k = 1; k < 3; ++k) { 55 if(a[n] == -1 || j == a[n]) 56 ans = (ans + dp[n][j][k]) % mod; 57 } 58 } 59 printf("%lld\n", ans); 60 return 0; 61 }
原文地址:https://www.cnblogs.com/zmin/p/9900301.html
时间: 2024-10-11 00:27:47