题目描述

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. Mac 安装cnpm

    1.先安装node   node的下载地址:http://nodejs.cn/download/   这个没什么好说的,安装完成后测试一下,在终端输入:node -v   这时候就可以看到安装的nod ...

  2. Java访问数组

    package java03; /* 使用动态初始化数组的时候,其中的元素会自动拥有一个默认值,规则如下: 如果是整数类型,默认为0 如果是浮点类型,默认为0.0 如果是字符类型,默认为'\u0000 ...

  3. Servlet中如何获取用户提交的查询参数或表单数据?

    ①HttpServletRequest的getParameter()方法. ②HttpServletRequest的getParameterValues()方法. ③HttpServletReques ...

  4. webpack 学习1 安装构建项目

    本文中使用的webpack版本是4+,请注意区分 node.js安装 node.js下载地址 选择较低版本的稳定版下载,下载完成后得到的是一个msi文件,点击安装即可 安装完毕以后新建一个文件夹,并在 ...

  5. 数组(R语言)

    myarray = <- array (vector, dimensions, dimnames) 例如,生成一个2*3*4的数组: dim1 <- c("A1",&q ...

  6. enumerate()(Python)

    >>> E=enumerate('spam') >>> E <enumerate object at 0x1021ceca8> >>> ...

  7. oralce存储过程

    简单的存储 create or replace procedure sayhelloworld as begin dbms_output.put_line('Hello World'); end;

  8. windows7+tomcat7+nginx1.11.3 +memcached

    测试的环境是windows7+tomcat7+nginx1.11.3 +memcached 安装方法网上很多就不多说了. 1.session共享需要这几个jar 包  下载地址 http://down ...

  9. Redis入门很简单之三【常见参数配置】

    Redis入门很简单之三[常见参数配置] 博客分类: NoSQL/Redis/MongoDB redisnosql缓存中间件memcached  Redis的一下常见设置都是通过对redis.conf ...

  10. C语言编译exe添加图标

    C语言是一门通用的计算机编程语言,可以直接编译为可执行文件.在windows下,可执行文件的后缀是exe,我们编写一个最简单的程序test.c: #include <stdlib.h> i ...