找单词 HDU-2082 母函数

HDU-2802

假设有x1个字母A, x2个字母B,… x26个字母Z,同时假设字母A的价值为1,字母B的价值为2,… 字母Z的价值为26。那么,对于给定的字母,可以找到多少价值<=50的单词呢?单词的价值就是组成一个单词的所有字母的价值之和,比如,单词ACM的价值是1+3+14=18,单词HDU的价值是8+4+21=33。(组成的单词与排列顺序无关,比如ACM与CMA认为是同一个单词)。

a i ≤ 20 a_i≤20 ai20

input

2
1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
9 2 6 2 10 2 2 5 6 1 0 2 7 0 2 2 7 5 10 6 10 2 10 6 1 9

output

7
379297

solution

总 方 案 : ∏ i = 1 26 ( 1 + x 2 i + x 3 i + ⋅ ⋅ ⋅ + x i ∗ a i ) , 从 1 到 26 , 从 50 到 0 , 从 1 到 a i 遍 历 总方案:\prod\limits_{i=1}^{26}(1 + x^{2i} +x^{3i}+···+x^{i*a_i}),从1到26,从50到0,从1到a_i遍历 i=126(1+x2i+x3i++xiai)1265001ai

code

//Siberian Squirrel
//#include<bits/stdc++.h>
#include<unordered_map>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cmath>

using namespace std;
typedef long long ll;

const double PI = acos(-1);
const double eps = 1e-7;
const int MOD = 3221225473;
const int N = 5e6 + 10;
const int UP = 50;

int f[60];
int limit;

inline ll solve(ll res = 0) {
    memset(f, 0, sizeof f);
    f[0] = 1;
    for(int i = 1; i <= 26; ++ i) {
        scanf("%d", &limit);
        for(int j = UP; j >= 0; -- j) {
            if(f[j] == 0) continue;
            for(int k = 1; j + k * i <= UP && k <= limit; ++ k) {
                f[j + k * i] += f[j];
            }
        }
    }
    for(int i = 1; i <= 50; ++ i)
        res += f[i];
    return res;
}

int main() {
#ifdef ACM_LOCAL
    freopen("input", "r", stdin);
    freopen("output", "w", stdout);
#endif
    int o = 1;
    scanf("%d", &o);
    while(o --) {
        printf("%lld\n", solve());
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值