Luo tribe Goblin Valley P2467 solution to a problem

Face questions

So hard so hard so hard ah ah ah ~ (WoW later when he absolutely dead child)

Done summed up his thoughts;

First, push the following three properties:

1. If both i and i + 1 are not adjacent, then we direct exchange of these two numbers can be composed of (this one is based on our state transition) a new series

2. Each number ai becomes (n + 1) -ai will be another number of columns, the opposite peaks and valleys and a new series of cases

3. volatility series have symmetry. For example: 14253 becomes 35214

 

Set f [i] [j] represents the number from 1 ~ i 1 is the state j is the number of species;

Depending on the nature 1, when j is not adjacent to the j-1, f [i] [j] = f [i] [j-1]

When j and j-1 adjacent to the time, f [i] [j] is to compute the number of i-1, j-1 for the first, but the number of program j-1 is a valley

The 2, (Property i-1 number, the number of programs for the first j-1, j-1 but to the valley) is equivalent to finding the number ((i-1, (( i-1) +1) - ( j-1)) for the first, j-1 is the number of peaks of the program);

那么f[i][j]=f[i-1][i-j-1];

 

综上 plants predicate, f [i] [j] = f [i] [j-1] + f [] i-1] [ij-1];

Due to data comparison of water, enough memory is provided, a two-dimensional array can AC off.

 

 

#include <bits/stdc++.h>
using namespace std;
int f[4201][4201];
int main()
{
    int n,p;
    cin>>n>>p;
    f[1][0]=1;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(i-j-1>=0) f[i][j]=f[i][j-1]+f[i-1][i-j-1];
            f[i][j]%=p;
        }    
    }
    long long ans=0;
    for(int i=1;i<=n;i++) ans=(ans+f[n][i])%p;
    cout<<(ans*2)%p;
} 

 

Guess you like

Origin www.cnblogs.com/kamimxr/p/11442909.html