CF 1093 F Vasya and Array

Title:

Given a sequence of integers with length n, a positive integer k and a positive integer len, all the numbers in the sequence are between 1 and k, or equal to 1.

If there are no consecutive identical numbers longer than len, the segments are good.

We can change - 1 to an integer between 1 and k, turn the sequence into a good one, find out the number of schemes, and take the model of 998244353.

 

Train of thought:

F[i][j] denotes the number of schemes for filling in the number J at the first position.

S[i] denotes the number of alternatives for filling in the first I positions

If i i s j or - 1, then I can be j: F[i][j]=s[i-1]

But there will be repetitions: __________________

How to delete this situation, first of all, the number of len intervals is either X or - 1.

The number of repetitions i s s[i-len]-f[i-len][j]. In the position of i-len, all the numbers that can be terminated except filling in J can be added with a paragraph X to get the state f[i][j]

#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<string>
#include<map>
#include<queue>
#include<vector>
#include<stack>
#define ll long long
#define maxn 4001000
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int P=998244353;
int n,k,len,cnt[101000][110],f[101000][110],s[101000],a[101000];
ll rd()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
void init()
{
    n=rd();k=rd();len=rd();
    rep(i,1,n) a[i]=rd();
    s[0]=1;
    rep(i,1,k)
        rep(j,1,n)
            cnt[j][i]=cnt[j-1][i]+(a[j]==i||a[j]==-1?1:0);
}
void work()
{
    memset(f,0,sizeof(f));
    rep(i,1,n)
    {
        rep(j,1,k)
        {
            if(a[i]!=-1&&a[i]!=j) continue;
            f[i][j]=s[i-1];
            if(i>=len&&cnt[i][j]-cnt[i-len][j]==len)
            {
                f[i][j]=(f[i][j]-s[i-len]+f[i-len][j])%P;
                f[i][j]=(f[i][j]+P)%P;
            }
        }
        rep(j,1,k)
            s[i]=(s[i]+f[i][j])%P;
    }
    printf("%d\n",s[n]);
}
int main()
{
    init();
    work();
}

 

Posted by Sravan on Tue, 26 Mar 2019 09:27:28 -0700