Let's count the binary tree together --------------------------------- dp

Insert picture description here

Insert picture description here

Analysis:
https://blog.csdn.net/qq_43690454/article/details/105292305
The same routine as this question.
Let f [i] [j]: represent the number of
state equations of the i node and m leaf nodes : f [i] [j] = f [i] [j] + f [im-1] [j-jj] * f [m] [jj]
m and jj can be enumerated

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
ll f[100][100];
ll n,m;
int main()
{

		memset(f,0,sizeof f);
		f[0][0]=f[1][1]=1;
		for(int i=1;i<=55;i++)
		{
			for(int j=1;j<=i;j++)
			{
				for(int k=0;k<i;k++)
				{
					for(int p=0;p<=j;p++)
					{
						f[i][j]=(f[i][j]+f[i-k-1][j-p]*f[k][p])%MOD;
					}
				}
			}
		 } 
		 
	while(~scanf("%lld %lld",&n,&m)){
		cout<<f[n][m]<<endl;
	}
}
Published 572 original articles · praised 14 · 10,000+ views

Guess you like

Origin blog.csdn.net/qq_43690454/article/details/105293351