NOIP simulation super tree

Ideas: First, not to mention hard to think this state title, first try to do something, dp [i] represents the number of paths i- super trees, it can be considered a direct transfer, and do not look at that question in view of the complex to the only need to draw two dunes and a tree root, we assume that the number of sub-tree path has been launched here, then what can we get? First, it is assumed = SUM DP [-I. 1] ^ 2

1. Central two subtrees sealing understand, immediately sum species,

2. The operator a separate root node, there are kinds of sum,

3. Left -> Root Root || -> left, selected from any of a root connected, 2 * dp [i-1] * dp [i-1]? there is a problem. . The two roads are connected together or has always been a way I added a way?

Be transferred to the stops here, which is no solution to a problem of a lot of things, how to define a state, then we can not tell in the end where to where to transfer, so we can subdivide the state, I was in combinatorial mathematics topics also some perception, DP seeking the number of programs, many programs is the so-called classification by status, in accordance with the link between stages to transfer. Then you can get the answer, and now the state classification is quite chaotic, in a state of cohabitation makes it difficult to transfer, so we put them paths are defined as mutually exclusive, ie no common point, but this is certainly incomplete, it for example, there are many paths intersect the original problem, then so can even recursive definition would not be able to get an answer, combined with the data range, we expect another increase in the state behind the one-dimensional, on behalf of what it, I do not want to elect j Article there are several paths intersect situation, so that the transfer 3 will be able to use several disjoint program can get, not Miya. . . Then this question is relatively simple, if there are still difficulties in transferring students to problem solutions DeepinC take a look , super-detailed! ! ! Chang also comes with card tricks

 

#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
const int K=320;
long long f[K][K];
int rd()
{
    char cc=getchar();
    long long s=0,w=1;
    while(cc<'0'||cc>'9') {if(cc=='-') w=-1;cc=getchar();}
    while(cc>='0'&&cc<='9') s=(s<<3)+(s<<1)+cc-'0',cc=getchar();
    return s*w;
}
int main()
{
    const int n=rd(),mod=rd();
    f[1][1]=f[1][0]=1%mod;
    for(register int i=1;i<=n;i++)
    {
        int kk=min(n-i+2,i<=9?1<<i:300);
        for(register int j=0;j<=kk+1;j++)
        {
            for(register int k=0;k<=kk+1;k++)
            {
                if(j+k>n+1)break;
                const register int sum=1ll*f[i][j]*f[i][k]%mod;
                f[i+1][j+k]=(f[i+1][j+k]+1ll*sum*(2*j+2*k+1));
                f[i+1][j+k+1]=(f[i+1][j+k+1]+sum);
                f[i+1][j+k-1]=(f[i+1][j+k-1]+1ll*sum*(j+k)*(j+k-1))%mod;
            }
        }
    }
    printf("%lld\n",f[n][1]);
}
/*
g++ 1.cpp -o 1
./1
3 100
*/
/*
g++ 1.cpp -o 1
./1
1 1
*/
View Code

 

Guess you like

Origin www.cnblogs.com/starsing/p/11211024.html