非原创codeforces - 1067A Array Without Local Maximumsdp

Posted zmin

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了非原创codeforces - 1067A Array Without Local Maximumsdp相关的知识,希望对你有一定的参考价值。

学习博客:戳这里

附本人代码:

技术分享图片
 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
", ans);
60     return 0;
61 }
View Code

 

以上是关于非原创codeforces - 1067A Array Without Local Maximumsdp的主要内容,如果未能解决你的问题,请参考以下文章

非原创codeforces 1029F Multicolored Markers 贪心+构造

非原创codeforces 1070C Cloud Computing 线段树&树状数组

codeforces 1029E Tree with Small Distances思维+贪心 非原创

Vasya And Array CodeForces - 1187C (构造)

Prime Number(CodeForces-359C)[快速幂/思维]

FutureWarning:不推荐使用非元组序列进行多维索引,使用 `arr[tuple(seq)]` 而不是 `arr[seq]`