HDU 1521 排列组合

HDU 1521 排列组合

题意:
(中文)
思路:
此题是一道指数型母函数的题目,
G(x) = (1 + x / 1! + x^2 / 2! + x^3 / 3! + …. + x^n1 / n1!)
* (1 + x / 1 ! + x^2 / 2! + … + x^n2 / n2!) * …
* (1 + x / 1! + x^2 / 2! + .. + x^nk / nk!).
先把阶层求出来,当计算的时候每次都除f[n],在最后还原系数的时候再乘上去。
Code:

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>

#define TEST

#define LL long long
#define Mt(f, x) memset(f, x, sizeof(f));
#define rep(i, s, e) for(int i = (s); i <= (e); ++i)
#ifdef TEST
    #define See(a) cout << #a << " = " << a << endl;
    #define See2(a, b) cout << #a << " = " << a << ' ' << #b << " = " << b << endl;
    #define debug(a, s, e) rep(_i, s, e) {cout << a[_i] << ' ';} cout << endl;
    #define debug2(a, s, e, ss, ee) rep(i_, s, e) {debug(a[i_], ss, ee)}
#else
    #define See(a)
    #define See2(a, b)
    #define debug(a, s, e)
    #define debug2(a, s, e, ss, ee)
#endif // TEST

const int MAX = 2e9;
const int MIN = -2e9;
const double eps = 1e-8;
const double PI = acos(-1.0);

using namespace std;

const int N = 100;

int f[N];
int a[N];
double c1[N], c2[N];

void init()
{
    f[0] = 1;
    for(int i = 1; i <= 13; ++i)
    {
        f[i] = f[i - 1] * i;
    }
}

int main()
{
    int n, m;
    init();
    while(~scanf("%d%d", &n, &m))
    {
        for(int i = 1; i <= n; ++i)
        {
            scanf("%d", &a[i]);
        }
        Mt(c1, 0);
        Mt(c2, 0);
        c1[0] = 1;
        for(int i = 1; i <= n; ++i)
        {
            for(int k = 0; k <= a[i]; ++k)
            {
                for(int s = 0; s + k <= m; ++s)
                {
                    c2[s + k] += c1[s] / f[k];
                }
            }
            for(int k = 0; k <= m; ++k)
            {
                c1[k] = c2[k];
                c2[k] = 0;
            }
        }
        printf("%.0f\n", c1[m] * f[m]);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值