题目描述

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. Web前端基础学习-2

    盒子模型 在页面中,我们将所有的元素全部看做是一个盒子,页面布局就是将大大小小不同的盒子堆砌在一起,而一个盒子由以下几部分组成: padding:内边距,内容到边框的距离: margin:外边距,其他 ...

  2. PHP应该学什么,如何学好PHP

    http://blog.sina.com.cn/s/blog_76bdabf70101azl4.html(注:原文来自传智播客) 本文转自http://blog.sina.com.cn/s/blog_ ...

  3. 【原创】微信最新表情js代码

    最近在做仿微信聊天表情发送功能,所以需要展示常用的105个表情. 因为对接微信公众号的时候,用户聊天过程中发送的表情,微信服务器会转成对应的代码传给我们的服务器,类似如下: :/::)/::~/::B ...

  4. 2018-2-13-win10-uwp-绑定密码

    title author date CreateTime categories win10 uwp 绑定密码 lindexi 2018-2-13 17:23:3 +0800 2018-2-13 17: ...

  5. java命令-jps

    jps命令,查看当前用户所有java进程pid 可进入/tmp/hsperfdata_xxx(登录用户名)路径下,可查看当前用户下所有的Java进程.jps.jconsole.jvisualvm等工具 ...

  6. 调试Spark应用

    本文摘自:<Hadoop专家-管理.调优与Spark|YARN|HDFS安全>Sam R. Alapati 一.通过日志聚合访问日志 二.当日志聚合未开启时

  7. c++使用不定参数

    定义不定参数,使用的宏有: va_start(ap, arg)  初始化一个va_list的变量ap va_arg(ap, type)  获取下一个type类型的参数 va_end(ap)  结束使用 ...

  8. testNG之顺序执行

    @Test   testNG1.java: import org.testng.annotations.Test; public class testNG1 { @Test public void t ...

  9. POJ A Plug for UNIX (最大流 建图)

    Description You are in charge of setting up the press room for the inaugural meeting of the United N ...

  10. 【从0到1,搭建Spring Boot+RESTful API+Shiro+Mybatis+SQLServer权限系统】04、统一处理异常

    本节讨论如何使用Spring的异常处理机制,当我们程序出现错误时,以相同的一种格式,把错误信息返回给客户端 1.创建一些自定义异常 public class TipsException extends ...