【非原创】codeforces - 1067A Array Without Local Maximums【dp】

学习博客:戳这里

附本人代码:

 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-08-05 16:34:20

【非原创】codeforces - 1067A Array Without Local Maximums【dp】的相关文章

codeforces 1068d Array Without Local Maximums dp

题目传送门 题目大意:给出一个长度为n的数组,这个数组有的数是给出的,有的数是固定的,且范围都在[1,200]之间,要求这个数组中,每一个数字都小于等于 前后两个数字的最大值,求方案数mod p. 思路:一眼看出是个dp,但是不太擅长这个,看了大佬的题解,又加上了一些自己的思考. 由于这个数组每一个元素都是前后相关的,所以应该是个线性dp的东西,既然是线性的,我们就先考虑每一个元素和前面一个元素的关系(没法往后看,因为后面的元素都没有得到),将当前这个数字和前面的数字进行比较,会得到">&

Codeforces 57C Array dp暴力找规律

题目链接:点击打开链接 先是计算非递增的方案, 若非递增的方案数为x, 则非递减的方案数也是x 答案就是 2*x - n 只需求得x即可. 可以先写个n3的dp,然后发现规律是 C(n-1, 2*n-1) 然后套个逆元即可. #include<iostream> #include<cstdio> #include<vector> #include<string.h> using namespace std; #define ll long long #def

发现一段精简的模板算法(非原创)

引用自: http://ejohn.org/blog/javascript-micro-templating/ // Simple JavaScript Templating // John Resig - http://ejohn.org/ - MIT Licensed (function(){ var cache = {}; this.tmpl = function tmpl(str, data){ // Figure out if we're getting a template, or

有关中小非原创小说网站SEO的思考

晃眼两年过去了,12年后自己开了家小公司,线下实体,网站这块都荒废了,前段时间闲着没事又捡起了闲置的域名,两年多没做了,只剩下不到20个域名,随便选了几个准备做小说网挂着,心不大,服务器和域名的费用收回就够了. 刚开始建了三个,本地调试好,放服务器应该不到3个小时,首页就被百度收录,这一点来说现在百度还是相对做的很不错的,是最快的(未发新外链),其次就是360搜索,大概第二天到第三天陆续收录了首页,最慢的当属搜狗了差不多接近一周才收录(如果不是小说站我是不会考虑搜狗的).其中一个相对比较幸运,开

新辰:SEOer如何降低非原创文章带来的影响?

1.相关资料 官方文档:http://htmlparser.sourceforge.net/samples.html API:http://htmlparser.sourceforge.net/javadoc/index.html 其它HTML 解释器:jsoup等.由于HtmlParser自2006年以后就再没更新,目前很多人推荐使用jsoup代替它. 2.使用HtmlPaser的关键步骤 (1)通过Parser类创建一个解释器 (2)创建Filter或者Visitor (3)使用parser

Linux下high CPU分析心得【非原创】

非原创,搬运至此以作笔记, 原地址:http://www.cnitblog.com/houcy/archive/2012/11/28/86801.html 1.用top命令查看哪个进程占用CPU高gateway网关进程14094占用CPU高达891%,这个数值是进程内各个线程占用CPU的累加值. PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND     14094 root      15   0  315m 

codeforces A. Array题解

Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: The product of all numbers in the first set is less than zero (?<?0). The product of all numbers in the secon

CSS样式命名整理(非原创)

非原创,具体出自哪里忘了,如果侵害您的利益,请联系我. CSS样式命名整理 页面结构 容器: container/wrap 整体宽度:wrapper 页头:header 内容:content 页面主体:main 页尾:footer 导航:nav 侧栏:sidebar 栏目:column 中间内容:center 导航 导航:nav 导航:mainbav/globalnav 子导航:subnav 顶导航:topnav 边导航:sidebar 左导航:leftsidebar 右导航:rightside

字符串相似度计算的方法,使用SQL以及C#实现,本文非原创摘自网络(.NET SQL技术交流群入群206656202需注明博客园)

1 CREATE function get_semblance_By_2words 2 ( 3 @word1 varchar(50), 4 @word2 varchar(50) 5 ) 6 returns nvarchar(4000) 7 as 8 begin 9 declare @re int 10 declare @maxLenth int 11 declare @i int,@l int 12 declare @tb1 table(child varchar(50)) 13 declare