Topic Links: Types of 51nod 1412 AVL trees
When I started to do it, I turned the depth too small. The result has been WA, I was naïve.
1#include <cstdio>2#include <cstring>3#include <algorithm>4#include <queue>5 using namespacestd;6typedefLong Longll;7 Const intMoD = 1e9+7;8 Const intN =2001;9ll dp[n][ -];//Dp[i][k] I: Number of nodes, K: DepthTen voidsolve () { One intI, J, K; Adp[0][0] = dp[1][1] =1; - for(i =2; i < N; ++i) { - for(k =2; K < -; ++k) { the for(j =0; J < I; ++j) { - //J is the number of nodes in the right subtree, and the sum of the i-1 nodes is - //The left and right sub-tree depth same -Dp[i][k] + = dp[i-1-j][k-1] * dp[j][k-1]; + //left and right sub-tree depth difference one -Dp[i][k] + =2* dp[i-1-j][k-2] * dp[j][k-1]; +DP[I][K]%=MoD; A } at } - } - } - intMain () { - intn, I; -ll ans =0; in solve (); -scanf"%d", &n); to for(i =1; I < -; ++i) { +Ans + =Dp[n][i]; - } theAns%=MoD; *printf"%lld\n", ans); $ return 0;Panax Notoginseng}
View Code
51nod 1412 AVL tree Type (DP)