DP
題目大意: 有一個數列,滿足且。現在有一些數不知道,問原數列的所有可能情況。
設表示前個數,第個數爲,的方案數。
發現原數列一定不存在峯,但可以是平的。那麼轉移式如下:
答案就是。的數組開不下,要把第一位滾掉。
注意一些細節。
代碼:
#include<cctype>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 100005
#define M 201
#define F inline
using namespace std;
const int p=998244353;
int n,ans,lst,f[2][M][3],s1[M],s2[M];
F char readc(){
static char buf[100000],*l=buf,*r=buf;
if (l==r) r=(l=buf)+fread(buf,1,100000,stdin);
return l==r?EOF:*l++;
}
F int _read(){
int x=0,f=1; char ch=readc();
while (!isdigit(ch)){ if (ch=='-') f=-1; ch=readc(); }
while (isdigit(ch)) x=(x<<3)+(x<<1)+(ch^48),ch=readc();
return x*f;
}
int main(){
n=_read();
for (int i=1;i<=n;i++){
int x=i&1,w=_read(); s1[0]=s2[0]=0; if (i==n) lst=w;
for (int j=0;j<M;j++) for (int k=0;k<3;k++) f[x][j][k]=0;
if (i==1)
if (~w) f[x][w][1]=1;
else for (int j=1;j<M;j++) f[x][j][0]=1;
else
if (~w){
f[x][w][0]=((f[x^1][w][0]+f[x^1][w][1])%p+f[x^1][w][2])%p;
f[x][w][1]=s1[w-1],f[x][w][2]=(s2[M-1]-s2[w]+p)%p;
}
else for (int j=1;j<M;j++){
f[x][j][0]=((f[x^1][j][0]+f[x^1][j][1])%p+f[x^1][j][2])%p;
f[x][j][1]=s1[j-1],f[x][j][2]=(s2[M-1]-s2[j]+p)%p;
}
if (i==2) for (int j=1;j<M;j++) f[x][j][2]=0;
for (int j=1;j<M;j++){
s1[j]=(((s1[j-1]+f[x][j][0])%p+f[x][j][1])%p+f[x][j][2])%p;
s2[j]=((s2[j-1]+f[x][j][0])%p+f[x][j][2])%p;
}
}
if (~lst) ans=(f[n&1][lst][0]+f[n&1][lst][2])%p;
else for (int i=1;i<M;i++) (ans+=(f[n&1][i][0]+f[n&1][i][2])%p)%=p;
return printf("%d",ans),0;
}