loj 6270 data structure of the board title

serious

This question obviously be offline for length, descending enumeration length, then \ (O (nlog ^ 2n) \) two-dimensional to a few pointsThen the T

The board will not be a problem, trained, trained, trained,

Consider a change in direction, from small to large enumeration, and then ask the answer is the length \ (\ le n \) legitimate contribution to reducing the length of the interval \ (\ le k_i-1 \ ) legitimate contribution to the interval. Then all equal and legitimate contribution interval contribution to reducing illegal contributions interval, the interval is clearly illegal left point \ (<L \) and the right end point \ (> R \) , these two situations are repeated under normal circumstances, but if only a statistical length \ (<\) current interrogation interval length \ (+ 1 \) range, then these two sections is not illegal to pay, because their intersection interval length than some current interrogation interval length \ (1 + \) large, and this section will also be included in the legitimate current interrogation interval length (1 \ +) \ within, so as to split each interrogation interval length $ \ Le \ (current interrogation interval length of \) + 1 \ (legal section the length of contribution minus \) legitimate contribution to the interval \ le k_i-1 $, and then from small to large enumeration length, adding qualifying range, maintenance can be used Fenwick tree

#include<bits/stdc++.h>
#define LL long long
#define uLL unsigned long long
#define db double

using namespace std;
const int N=500+10,mod=1024523;
int rd()
{
    int x=0,w=1;char ch=0;
    while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return x*w;
}
void ad(int &x,int y){x+=y,x-=x>=mod?mod:0;}
char cc[N],ss[N];
int n,m,f[2][N][N];

int main()
{
    n=rd(),m=rd();
    scanf("%s%s",cc+1,ss+1);
    reverse(cc+1,cc+n+1),reverse(ss+1,ss+m+1);
    int nw=1,la=0;
    f[la][1][1]=1;
    for(int i=1;i<=n+m;++i)
    {
        for(int j=1;j<=n+1;++j)
            for(int k=1;k<=n+1;++k)
            {
                if(!f[la][j][k]) continue;
                int jj=i+1-j,kk=i+1-k;
                if(j<=n&&k<=n&&cc[j]==cc[k]) ad(f[nw][j+1][k+1],f[la][j][k]);
                if(j<=n&&kk<=m&&cc[j]==ss[kk]) ad(f[nw][j+1][k],f[la][j][k]);
                if(jj<=m&&k<=n&&ss[jj]==cc[k]) ad(f[nw][j][k+1],f[la][j][k]);
                if(jj<=m&&kk<=m&&ss[jj]==ss[kk]) ad(f[nw][j][k],f[la][j][k]);
                f[la][j][k]=0;
            }
        nw^=1,la^=1;
    }
    printf("%d\n",f[la][n+1][n+1]);
    return 0;
}

Guess you like

Origin www.cnblogs.com/smyjr/p/11374211.html