短小精悍的代码
dp[i][j] +=dp[k][j-1]*[i-k-1][j-1] i个结点 J层
1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<stdlib.h> 5 #include<algorithm> 6 using namespace std; 7 #define LL __int64 8 LL dp[40][40]; 9 int main() 10 { 11 int i,j,k,n,d; 12 scanf("%d%d",&n,&d); 13 for(i = 0; i <= n ; i++) 14 dp[0][i] = 1; 15 for(i = 1; i <= n ; i++) 16 { 17 for(j = 1; j <= n ; j++) 18 { 19 for(k = 0 ; k < i ; k++) 20 dp[i][j]+=dp[k][j-1]*dp[i-k-1][j-1]; 21 } 22 } 23 printf("%I64d ",dp[n][n]-dp[n][d-1]); 24 return 0; 25 }