Interpretations [BZOJ1925] [SDOI2010] Goblin tribes

Face questions

Resolve

This does not seem to talk about ah

Set \ (f [i] [j ] \) expressed \ (I \) mountain,

Finally reaching the height of a mountain is \ (i \) seat for the first \ (j \) large,

And the last mountain valley.

Note, \ (i \) are representatives \ (i \) is a mountain, does not mean necessarily the height \ (1 \) ~ \ (i \) .

\ (j \) is similar to a discrete thing .

We then consider setting \ (G [i] [J] \) ,

In addition to last mountain peaks other than that defined and \ (f [i] [j ] \) the same.

Then there formula \ (F [I] [J] = \ sum_ {J} = K-I. 1} ^ {G [. 1-I] [K] \) .

Here to talk about the maximum and minimum problems,

The maximum value can easily get to the big,

But before considering the \ (i \) before the last of a certain ratio of the mountain \ (i-1 \) small (as is the valley) seat,

So the last one is the first \ (j \) big that it is a front front \ (i-1 \) is a mountain in the ranking can not be less than \ (j \) .

(May express a little less clear, with inductive understand it.)

There is one obvious thing,

If there is a legitimate program,

Then we put the height of each mountain of \ (h_i \) into \ (the n-H_i-+ 1 \) , the program is still legal (that is, the mountain into the valley).

Thus \ (G [I] [J] = F [I] [I-J +. 1] \) .

The combined bit becomes \ (F [I] [J] = \ sum_. 1} ^ {K = {F} ij of [. 1-I] [K] \) .

And this is equivalent to a suffix and stuff.

Thus DP is the formula \ (F [I] [J] = F [I] [J +. 1] + F [. 1-I] [ij of] \) .

Optimization of space on the line under a rolling array.

#include <iostream>
#include <cstdio>
#include <cstring>
#define fre(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
using namespace std;

inline int read(){
    int sum=0,f=1;char ch=getchar();
    while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0' && ch<='9'){sum=sum*10+ch-'0';ch=getchar();}
    return f*sum;
}

const int N=4301;
int n,Mod,f[2][N];
int ans=0;

int main(){
    n=read();Mod=read();
    f[1][1]=1;int now=1;
    for(int i=2;i<=n;i++){
        now^=1;memset(f[now],0,sizeof(f[now]));
        for(int j=i-1;j;j--) f[now][j]=(f[now][j+1]+f[now^1][i-j])%Mod;
    }
    for(int i=1;i<=n;i++) ans=(ans+f[now][i])%Mod;
    printf("%d\n",(ans<<1)%Mod);
    return 0;
}

Guess you like

Origin www.cnblogs.com/zsq259/p/11416009.html