Codeforces Round #518 (Div. 2) D(计数DP)
#include<bits/stdc++.h>
using namespace std;
const long long mod=998244353;
int n;
int a[100007];
long long dp[100007][207][3];//第i位值为j时k是否成立,k=0,i<i-1,k=1,i==i-1,k=2,i>i-1

int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=1;i<=200;i++){
if(a[1]!=-1&&a[1]!=i)
dp[1][i][0]=0;
else
dp[1][i][0]=1;
dp[1][i][1]=dp[1][i][2]=0;
}
long long sum=0;
for(int i=2;i<=n;i++){
sum=0;
for(int x=1;x<=200;x++){
if(a[i]!=-1&&a[i]!=x)
dp[i][x][0]=0;
else
dp[i][x][0]=sum;
sum+=(dp[i-1][x][0]+dp[i-1][x][1]+dp[i-1][x][2])%mod;
sum%=mod;
}
for(int x=1;x<=200;x++){
if(a[i]!=-1&&a[i]!=x)
dp[i][x][1]=0;
else
dp[i][x][1]=(dp[i-1][x][0]+dp[i-1][x][1]+dp[i-1][x][2])%mod;
}
sum=0;
for(int x=200;x>=1;x--){
if(a[i]!=-1&&a[i]!=x)
dp[i][x][2]=0;
else
dp[i][x][2]=sum;
sum+=(dp[i-1][x][1]+dp[i-1][x][2])%mod;
sum%=mod;
}
}
long long ans=0;
for(int i=1;i<=200;i++)
ans+=(dp[n][i][1]+dp[n][i][2])%mod,ans%=mod;
printf("%lld",ans);
return 0;
}
Codeforces Round #518 (Div. 2) D(计数DP)的更多相关文章
- Codeforces Round #518 (Div. 2) [Thanks, Mail.Ru!]
Codeforces Round #518 (Div. 2) [Thanks, Mail.Ru!] https://codeforces.com/contest/1068 A #include< ...
- Codeforces Round #131 (Div. 1) B. Numbers dp
题目链接: http://codeforces.com/problemset/problem/213/B B. Numbers time limit per test 2 secondsmemory ...
- Codeforces Round #131 (Div. 2) B. Hometask dp
题目链接: http://codeforces.com/problemset/problem/214/B Hometask time limit per test:2 secondsmemory li ...
- Codeforces Round #276 (Div. 1) D. Kindergarten dp
D. Kindergarten Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/proble ...
- Codeforces Round #260 (Div. 1) A - Boredom DP
A. Boredom Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/455/problem/A ...
- Codeforces Round #533 (Div. 2) C.思维dp D. 多源BFS
题目链接:https://codeforces.com/contest/1105 C. Ayoub and Lost Array 题目大意:一个长度为n的数组,数组的元素都在[L,R]之间,并且数组全 ...
- Codeforces Round #539 (Div. 2) 异或 + dp
https://codeforces.com/contest/1113/problem/C 题意 一个n个数字的数组a[],求有多少对l,r满足\(sum[l,mid]=sum[mid+1,r]\), ...
- Codeforces Round #374 (Div. 2) C. Journey DP
C. Journey 题目连接: http://codeforces.com/contest/721/problem/C Description Recently Irina arrived to o ...
- Codeforces Round #202 (Div. 1) D. Turtles DP
D. Turtles Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/547/problem/B ...
随机推荐
- 与STL文件相关的各类学习地址
几个网址: 1.STL :https://en.wikipedia.org/wiki/STL_(file_format)#ASCII_STL 2.一个博客的文章地址: 三维图形数据格式 STL的 读取 ...
- 大数据日志分析产品——SaaS Cloud, e.g. Papertrail, Loggly, Sumo Logic;Open Source Frameworks, e.g. ELK stack, Graylog;Enterprise Products, e.g. TIBCO LogLogic, IBM QRadar, Splunk
Learn how you can maximize big data in the cloud with Apache Hadoop. Download this eBook now. Brough ...
- AngularJS学习笔记(一) 关于MVVM和双向绑定
写在前面: 因为需要开始学习ng,之前在知乎上听大神们介绍ng的时候说这个坑如何的大,学了一阵(其实也就三天),感觉ng做的很大很全,在合适的情境你可以完全使用ng搞定一切.这一点从诸如jqLite之 ...
- 什么是DMIPS
MIPS: Million Instructions executed Per Second,每秒百万条指令,用来计算同一秒内系统的处理能力 DMIPS: Dhrystone Million Inst ...
- [原]NYOJ-数的位数-69
大学生程序代写 /* NYOJ69 阶乘数位长度 http://acm.nyist.net/JudgeOnline/problem.php?pid=69 数的长度 时间限制:3000 ms | ...
- Gym - 100851G:Generators(人尽皆知但是WA题)
题意:现在有函数,每一项Xi=(A*X(i-1)+B)%C.现在给定N个函数以及K:X0,A,B,C.然你再每个函数选择一个数,使得其和最大,而且不被K整除. X0,A,B,C<=1e3 :K& ...
- Operating System-Thread(4) 线程的调度激活机制(Scheduler Activations)
本文主要介绍线程的调度激活机制(Scheduler Activations),主要内容: 调度激活机制简介 上行调用(upcall) 中断处理(Interrupt) 一. 调度激活机制简介 上一篇文章 ...
- bzoj 3994 约数个数和 —— 反演+数论分块
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3994 推导过程和这里一样:https://www.cnblogs.com/MashiroSk ...
- IPC的使用
IPC,Inter-Processor Communication是SYS/BIOS处理核间通信的组件: IPC的几种应用方式: 1.最小使用(Minimal use) 这种情况是通过核间的通知机制( ...
- 1 slow requests are blocked > 32 sec解决方法
[root@node1 ~]# ceph -s cluster: id: b8b4aa68-d825-43e9-a60a-781c92fec20e health: HEALTH_WARN Reduce ...