题目:问n个节点构成完全对称的树有多少种方法。
因为树是完全对称的,所以它的子树也是完全对称的。
对于每个树,拿出一个根节点,枚举剩下的节点能拆分成多少个子树。
#include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> #define LL long long int using namespace std; const int MAXN = 1010; const LL MOD = 1e9 + 7; LL dp[MAXN]; int main() { dp[1] = 1; for ( int i = 2; i <= 1000; ++i ) { int v = i - 1; for ( int j = 1; j*j <= v; ++j ) if ( v % j == 0 ) { dp[i] = ( dp[i] + dp[j] ) % MOD; if ( j * j != v ) dp[i] = ( dp[i] + dp[ v / j ] ) % MOD; } } int cas = 0; int n; while ( scanf("%d", &n ) == 1 ) { printf("Case %d: %lld ", ++cas, dp[n] ); } return 0; }