题目描述

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. 2019牛客多校第一场E ABBA 贪心 + DP

    题意:问有多少个有(n + m)个A和(n + m)个B的字符串可以凑出n个AB和m个BA. 思路:首先贪心的发现,如果从前往后扫,遇到了一个A,优先把它看成AB的A,B同理.这个贪心策略用邻项交换很 ...

  2. LeetCode--Longest Consecutive Sequence(最长连续序列) Python

    题目描述: Longest Consecutive Sequence(最长连续序列) 中文: 给定一个未排序的整数数组,找出最长连续序列的长度. 要求算法的时间复杂度为 O(n). 英文: Given ...

  3. jQuery实现网页放大镜功能 转载

    京东等电商网站中可以对商品进行放大观察,本文要实现的就是模仿这个放大镜功能,大致效果如下图所示: 简要说明实现思路: 1.原图窗口与放大窗口插入的是同一个图片,不过原图窗口的图片要适当缩小,放大窗口图 ...

  4. jQuery 菜单 垂直菜单实现

    HTML <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <ti ...

  5. idea maven打jar包

    双击clean install 会在根目录targer生成文件(注意删除test和替换yml文件)

  6. hdu 1757 A Simple Math Problem (矩阵快速幂)

    Description Lele now is thinking about a simple function f(x). If x < 10 f(x) = x. If x >= 10 ...

  7. 【Shiro】六、Apache Shiro Session管理

    1.Session的介绍 关于Session 会话:从启动一个Session到关闭这个Session作为一个会话,是对客户端和服务器端交互的一种封装,带有时效性 会话的产生: 一般从容器中产生 Web ...

  8. 《一头扎进》系列之Python+Selenium框架实战篇7 - 年底升职加薪,年终奖全靠它!Merry Christmas

    1. 简介 截止到上一篇文章为止,框架基本完全搭建完成.那么今天我们要做什么呢????聪明如你的小伙伴或者是童鞋一定已经猜到了,都测试完了,当然是要生成一份高端大气上档次的测试报告了.没错的,今天宏哥 ...

  9. 漫谈C语言结构体【转】

    相信大家对于结构体都不陌生.在此,分享出本人对C语言结构体的学习心得.如果你发现这个总结中有你以前所未掌握的,那本文也算是有点价值了.当然,水平有限,若发现不足之处恳请指出.代码文件test.c我放在 ...

  10. 个人笔记 - MATLAB

    1.教程 2.基本知识 2.1 帮助文档设置成中文:链接1 2.2 多行注释: 链接1 2.3 MATLAB基本数据类型: 链接1  链接2 2.4 matlab中的 ndims(a).length( ...