zoukankan      html  css  js  c++  java
  • HDU 4489 The King's Ups and Downs

    HDU 4489 The King's Ups and Downs

    思路:

    状态:dp[i]表示i个数的方案数。

    转移方程:dp[n]=∑dp[j-1]/2*dp[n-j]/2*C(n-1,j-1)。

    代码:

    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define pb push_back
    #define mem(a,b) memset(a,b,sizeof(a))
    
    const int N=55;
    ll dp[N];
    ll C(ll n,ll m)
    {
        ll t1=1,t2=1;
        if(n-m<m)m=n-m;
        for(int i=0;i<m;i++)
        {
            t1*=(n-i);
            t2*=(i+1);
        }
        return t1/t2;
    }
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        int n,a,b;
        dp[0]=dp[1]=2;
        for(int i=2;i<=20;i++)
        {
            ll tot=0;
            for(int j=1;j<=i;j++)
            {
                tot+=dp[j-1]/2*dp[i-j]/2*C(i-1,j-1);
            }
            dp[i]=tot;
        }
        dp[1]=1;
        cin>>n;
        while(n--)
        {
            cin>>a>>b;
            cout<<a<<' '<<dp[b]<<endl;
        } 
        return 0;
    } 
  • 相关阅读:
    申请奖励加分
    6.14
    6.11
    6.10
    6.9
    6.8
    6.7
    6.6
    6.5
    6.4
  • 原文地址:https://www.cnblogs.com/widsom/p/7732013.html
Copyright © 2011-2022 走看看