zoukankan      html  css  js  c++  java
  • HDU 4472 Count (DP)

    题目:问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;
    }
  • 相关阅读:
    ES6
    django创建超级用户
    小程序-网络请求api
    小程序-数据双向绑定
    POJ2406 Power Strings
    POJ2758 Checking the Text
    LightOJ1197
    51Nod
    CF55D
    Kattis
  • 原文地址:https://www.cnblogs.com/GBRgbr/p/3360227.html
Copyright © 2011-2022 走看看