CF9D How many trees?

Jennie

搞出一个二维dp'还是比较显然的

#include<cstdio>
#include<iostream>
#include<cstring>
#include<iomanip>
#include<cmath>
#include<algorithm>
#define int long long
using namespace std;
template<class T>inline void read(T &x)
{
    x=0;register char c=getchar();register bool f=0;
    while(!isdigit(c))f^=c=='-',c=getchar();
    while(isdigit(c))x=(x<<3)+(x<<1)+(c^48),c=getchar();
    if(f)x=-x;
}
template<class T>inline void print(T x)
{
    if(x<0)putchar('-'),x=-x;
    if(x>9)print(x/10);
    putchar('0'+x%10);
}
int n,m;
int f[50][50];
signed main(){
	read(n);
	read(m);
	f[0][0]=1;
	for(int i=1;i<=n;++i){
		for(int j=1;j<=n;++j){
			for(int l=0;l<i;++l){
				int r=i-l-1;
				for(int z=0;z<j;++z){
					f[i][j]+=(f[l][j-1]*f[r][z]*2);
					if(j-1==z){
						f[i][j]-=(f[l][j-1]*f[r][z]);
					}
				}
			}
		}
	}
	long long ans=0;
	for(int i=m;i<=n;++i){
		ans+=f[n][i];
	}
	cout<<ans;
	return 0;
}
posted @ 2021-10-21 22:59  Simex  阅读(36)  评论(0编辑  收藏  举报