题目描述

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. WPFの触发器详解

    例子1 简单触发器Triggers——满足简答的条件,触发 <Window x:Class="Styles.SimpleTriggers" xmlns="http: ...

  2. Razor 保存动态表格

    本文转载自  ASP.NET MVC数组模型绑定 ,https://www.cnblogs.com/choon/p/5429065.html 内容根据评论内容中的方式有所调整 在ASP.NET MVC ...

  3. 由hbase.client.scanner.caching参数引发的血案(转)

    转自:http://blog.csdn.net/rzhzhz/article/details/7536285 环境描述 Hadoop 0.20.203.0Hbase 0.90.3Hive 0.80.1 ...

  4. 【归纳】springboot中的IOC注解:注册bean和使用bean

    目前了解的springboot中IOC注解主要分为两类: 1. 注册bean:@Component和@Repository.@Service.@Controller .@Configuration 共 ...

  5. Java8使用实现Runnable接口方式创建新线程的方法

    环境介绍 JDK版本:1.8 开发架构:spring boot 2.x 日志:slf4j 实现步骤 Runnable接口中只有一个run()方法,它是非Thread类子类的类提供的一种激活方式.一个类 ...

  6. mitmproxy 代理介绍及入门

    转载请注明出处 https://www.cnblogs.com/majianming/p/11823669.html mitmproxy 是一个python 写成的代理工具,可以代理https.htt ...

  7. django 邮箱发送

    在django中提供了邮件接口 QQ邮箱配置 qq邮箱地扯:https://mail.qq.com settings文件 # 邮箱配置 EMAIL_USE_SSL = True EMAIL_HOST ...

  8. 初识localstorage用法

    最近在做一个类似填报信息的页面,一共有8页,当点击切换到下一页的时候要求把上一页的数据存到本地,以便下次切换到这个页面的时候自动把值填上去,并且在最后一页提交数据的时候直接用localstorage里 ...

  9. Reverse array

    数组颠倒算法 #include <iostream> #include <iterator> using namespace std; void reverse(int* A, ...

  10. 饿了么 <el-input></el-input>输入框获取与失去焦点事件

    //1.定义focus事,绑定属性 <el-input v-model="headerInput" @focus="onInputFocus" @blur ...