Test instructions gives the type of AVL number to n nodes
The depth of the tree is small
Then the transfer equation is obvious.
Dp[i][j] represents the species of a tree with a node n depth of J
K is the number of Zuozi nodes
Dp[i][j+1] + = dp[k][j]*dp[i-k-1][j];
Dp[i][j+1] + = 2*dp[k][j-1]*dp[i-k-1][j];
#include <stdio.h>#include<iostream>#include<algorithm>#include<string.h>#include<math.h>using namespacestd;Const Long LongMOD =1000000007; typedefLong Longll;ll dp[2100][ -];//I means the number of J indicates the depthLL Check (intXinty) { return 0;}voidinit () {dp[0][0] = dp[1][1] =1; //dp[i][j+1] + = dp[k][j]*dp[i-k-1][j]; //dp[i][j+1] + = 2*dp[k][j-1]*dp[i-k-1][j]; for(intI=2; i<= -; i++) { for(intj=0; j<= -; j + +) { for(intk=0; k<i;k++) {dp[i][j+1] + = dp[k][j]*dp[i-k-1][j]; Dp[i][j+1] +=2*dp[k][j-1]*dp[i-k-1][j]; Dp[i][j+1]%=MOD; } } }}intMain () {//0 0//1 1//2 2//3init (); intN; CIN>>N; ll ans=0; for(intI=0;i< -; i++) {ans+=Dp[n][i]; } cout<<ans%MOD<<Endl; return 0;}
AC Code
Type of 51nod 1412 AVL number (DP