ICPC2008 Harbin -A-Array Without Local Maximums

Title Description

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.

Entry

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.

Export

Print number of ways to restore the array modulo 998244353.

Sample input

3
1 -1 2

Sample Output

1
Title intended 
to construct a sequence of length n, there are positions is - . 1 , can fill 1- numeral 200, such that each position to be smaller than the maximum value of its left and right sides, the number of programs seeking 

idea 
DP 
F [I] [ J] [ 0 / . 1 / 2 ] denotes the i-th bit, the current number j, from i-1 to i is a rising / equal / decrease in the number of programs 
is clearly 
F [i] [J] [ 0 ] = F [i - . 1 ] [K] [ 0 ] + F [I- . 1 ] [K] [ . 1 ] + F [I- . 1 ] [K] [ 2 ]; K < J; 
F [I] [J] [ . 1 ] F = [I- . 1 ] [K] [ 0 ] + F [I- . 1 ] [K] [ . 1 ] + F [I- . 1 ] [K] [ 2 ]; K =j
f[i][j][2]=f[i-1][k][1]+f[i-1][k][2];
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int P=998244353;
const int N=1e5+10;
ll f[N][205][3];
ll sum[2][205][3];
int a[N];
int n;
int main(){
    scanf("%d",&n);
    for (int i=1;i<=n;i++) scanf("%d",&a[i]);
 
    if (a[1]==-1)
    {
        for (int i=1;i<=200;i++) f[1][i][0]=1;
    } else f[1][a[1]][0]=1;
 
    for(int i = 1; i <= 200; i++) sum[0][i][0] = (sum[0][i-1][0] + f[1][i][0])%P;
 
    for (int i=2;i<=n;i++) {
        //sum[!(i&1)][0][0] = sum[!(i&1)][0][1] = sum[!(i&1)][0][2] = 0;
        for (int j=1;j<=200;j++) {
        if (a[i]==-1 ||  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][0]=((sum[i&1][j-1][0]+sum[i&1][j-1][1])%P+sum[i&1][j-1][2])%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][1]=(f[i-1][j][0]+f[i-1][j][1]+f[i-1][j][2])%P;
            //f[i][j][2]=(f[i][j][2]+f[i-1][k][1]+f[i-1][k][2])%p;
            f[i][j][2]=((sum[i&1][200][1] - sum[i&1][j][1] +P)%P + (sum[i&1][200][2] - sum[i&1][j][2]+P)%P)%P;
 
        }
        sum[!(i&1)][j][0] = (sum[!(i&1)][j-1][0] + f[i][j][0])%P;
        sum[!(i&1)][j][1] = (sum[!(i&1)][j-1][1] + f[i][j][1])%P;
        sum[!(i&1)][j][2] = (sum[!(i&1)][j-1][2] + f[i][j][2])%P;
        }
    }
   // cout<<f[1][a[1]][0]<<' '<<f[1][a[1]][1]<<' '<<f[1][a[1]][2]<<endl;
    ll ans=0;
    if (a[n]==-1)
    {
        for (int i=1;i<=200;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]);])%2] + f [n] [i] [1
            Yr = (year + f [n] [i] [P;
        }
    } else ans=(f[n][a[n]][1]+f[n][a[n]][2])%P;
    printf("%lld\n",ans);
    return 0;
}
View Code

 

k> J 
enumeration if k is 200 * 200 * the n-, so to prefix and optimize ...... but probably written too strange

 

 

Guess you like

Origin www.cnblogs.com/tetew/p/11317677.html