题目描述

Ivan unexpectedly saw a present from one of his previous birthdays. It is array of n numbers from 1 to 200. Array is old and some numbers are hard to read. Ivan remembers that for all elements at least one of its neighbours ls not less than it, more formally:
a1≤a2,
an≤an−1 and
ai≤max(ai−1,ai+1) for all i from 2 to n−1.
Ivan does not remember the array and asks to find the number of ways to restore it. Restored elements also should be integers from 1 to 200. Since the number of ways can be big, print it modulo 998244353.

输入

First line of input contains one integer n (2≤n≤105) — size of the array.

Second line of input contains n integers ai — elements of array. Either ai=−1 or 1≤ai≤200. ai=−1 means that i-th element can't be read.

输出

Print number of ways to restore the array modulo 998244353.

样例输入

3
1 -1 2

样例输出

1
题意
构造一个长度为n的序列,有些位置是-,可以填1-200的数字,要使得每个位置都比它左右两侧的最大值小,求方案数 思路
dp
f[i][j][//]表示到第i位,当前数为j,从i-1到i是上升/相等/下降的方案数
显然
f[i][j][]=f[i-][k][]+f[i-][k][]+f[i-][k][]; k<j;
f[i][j][]=f[i-][k][]+f[i-][k][]+f[i-][k][]; k=j
f[i][j][]=f[i-][k][]+f[i-][k][];
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int P=;
const int N=1e5+;
ll f[N][][];
ll sum[][][];
int a[N];
int n;
int main(){
scanf("%d",&n);
for (int i=;i<=n;i++) scanf("%d",&a[i]); if (a[]==-)
{
for (int i=;i<=;i++) f[][i][]=;
} else f[][a[]][]=; for(int i = ; i <= ; i++) sum[][i][] = (sum[][i-][] + f[][i][])%P; for (int i=;i<=n;i++) {
//sum[!(i&1)][0][0] = sum[!(i&1)][0][1] = sum[!(i&1)][0][2] = 0;
for (int j=;j<=;j++) {
if (a[i]==- || a[i]==j)
{
//f[i][j][0]=f[i-1][k][0]+f[i-1][k][1]+f[i-1][k][2]; k<j;
f[i][j][]=((sum[i&][j-][]+sum[i&][j-][])%P+sum[i&][j-][])%P;
//f[i][j][1]=f[i-1][k][0]+f[i-1][k][1]+f[i-1][k][2]; k=j
f[i][j][]=(f[i-][j][]+f[i-][j][]+f[i-][j][])%P;
//f[i][j][2]=(f[i][j][2]+f[i-1][k][1]+f[i-1][k][2])%p;
f[i][j][]=((sum[i&][][] - sum[i&][j][] +P)%P + (sum[i&][][] - sum[i&][j][]+P)%P)%P; }
sum[!(i&)][j][] = (sum[!(i&)][j-][] + f[i][j][])%P;
sum[!(i&)][j][] = (sum[!(i&)][j-][] + f[i][j][])%P;
sum[!(i&)][j][] = (sum[!(i&)][j-][] + f[i][j][])%P;
}
}
// cout<<f[1][a[1]][0]<<' '<<f[1][a[1]][1]<<' '<<f[1][a[1]][2]<<endl;
ll ans=;
if (a[n]==-)
{
for (int i=;i<=;i++)
{
// printf("f[3][%d][0]=%lld,f[3][%d][1]=%lld,f[3][%d][2]=%lld\n",i,f[3][i][0],i,f[3][i][1],i,f[3][i][2]);
ans=(ans+f[n][i][]+f[n][i][])%P;
}
} else ans=(f[n][a[n]][]+f[n][a[n]][])%P;
printf("%lld\n",ans);
return ;
}
k>j
枚举k的话是200**n,所以要前缀和优化……但可能写的过于诡异

ICPC2008哈尔滨-A-Array Without Local Maximums的更多相关文章

  1. 【计数dp】Array Without Local Maximums

    参考博客:[CF1068D]Array Without Local Maximums(计数DP) [题意] n<=1e5 dp[i][j][k]表示当前第i个数字为j,第i-1个数字与第i个之间 ...

  2. codeforces 1068d Array Without Local Maximums dp

    题目传送门 题目大意:给出一个长度为n的数组,这个数组有的数是给出的,有的数是固定的,且范围都在[1,200]之间,要求这个数组中,每一个数字都小于等于 前后两个数字的最大值,求方案数mod p. 思 ...

  3. 【CF1068D】Array Without Local Maximums(计数DP)

    题意: n<=1e5 思路:卡内存 dp[i][j][k]表示当前第i个数字为j,第i-1个数字与第i个之间大小关系为k的方案数(a[i-1]<a[i],=,>) 转移时使用前缀和和 ...

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

    学习博客:戳这里 附本人代码: 1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 co ...

  5. 「题解报告」CF1067A Array Without Local Maximums

    大佬们的题解都太深奥了,直接把转移方程放出来让其他大佬们感性理解,蒟蒻们很难理解,所以我就写了一篇让像我一样的蒟蒻能看懂的题解 原题传送门 动态规划三部曲:确定状态,转移方程,初始状态和答案. --神 ...

  6. ICPC2008哈尔滨-E-Gauss Elimination

    题目描述 Li Zhixiang have already been in “Friendship” ocean-going freighter for three months. The excit ...

  7. Codeforces 1068 - A/B/C/D/E - (Done)

    链接:http://codeforces.com/contest/1068 A - Birthday - [计算题] 题意:一共 $N$ 种硬币,我已经有其中 $K$ 种,我的 $M$ 个朋友每人送我 ...

  8. [Swift]LeetCode775. 全局倒置与局部倒置 | Global and Local Inversions

    We have some permutation Aof [0, 1, ..., N - 1], where N is the length of A. The number of (global) ...

  9. 图像矫正-基于opencv实现

    一.引言 上篇文章中四种方法对图像进行倾角矫正都非常有效.Hough变换和Radon相似,其抗干扰能力比较强,但是运算量大,程序执行慢,其改进方法为:我们可以不对整幅图像进行操作,可以在图像中选取一块 ...

随机推荐

  1. 页面加载时loading效果

    页面加载时loading效果: <!DOCTYPE html> <html lang="en"> <head> <meta charset ...

  2. 三、IIS通过目录方式部署以供外部调试

    一.IIS 下面是通过 gif 为 因项目是bin生成后的,非运行方式的调试,所以断点调试无效,仅修改文件后,右击项目重新生成解决方案即可,好处:启动快,坏处:不可以断点调试查看变量和分步执行语句.

  3. Ansible--03 ansible 变量

    目录 Ansible 变量 变量概述 定义变量的方式 如何定义变量 Ansible变量优先级测试 变量注册 ansibl e层级定义变量 facts缓存 Ansible 变量 变量概述 变量提供了便捷 ...

  4. bash date format

    Bash Date To format Bash Date to a required one, bash shell provides date command along with many fo ...

  5. 笔记73 高级SSM整合2

    遇到的问题: 1.表单信息校验:jQuery前端校验,ajax用户名重复校验,重要信息后端校验(JSR303)+数据库约束 2.在设置下拉列表显示的值时出现问题. 3.邮箱也添加重复性校验 4.pub ...

  6. 一次峰回路转的getshell

    扫目录发现 http://www.xxx.test.cn/bak/以及/bak/upload.jsp

  7. leetcode-第14周双周赛-1273-删除树节点

    题目描述: 自己的提交:动态规划 class Solution: def deleteTreeNodes(self, nodes: int, parent: List[int], value: Lis ...

  8. Spring整合SpringDataJpa配置文件头

    <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.spr ...

  9. 【JS】js引擎执行过程

    概述 js引擎执行过程主要分为三个阶段,分别是语法分析,预编译和执行阶段,上篇文章我们介绍了语法分析和预编译阶段,那么我们先做个简单概括,如下: 语法分析: 分别对加载完成的代码块进行语法检验,语法正 ...

  10. 【InnoDB】缓冲池

    索引目录 INNODB的体系结构 缓冲池 缓存中页的定位: checkpoint技术 INNODB的关键特性 插入缓冲 change buffer 两次写 以下的资料总结自:官方文档和<MySQ ...