HDU2082(母函数)

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define maxn 1111
#define maxm 1111111

long long a[55], b[55];
int n;

int main () {
    //freopen ("data.txt", "r", stdin);
    int t;
    cin >>t;
    while (t--) {
        memset (a, 0, sizeof a);
        cin >> n;
        for (int i = 0; i <= n && i <= 50; i++)
            a[i] = 1;
        for (int i = 2; i <= 26; i++) {
            memset (b, 0, sizeof b);
            cin >> n;
            for (int j = 0; j <= 50 && j <= i*n; j += i) {
                for (int k = 0; k <= 50; k++) {
                    if (j+k <= 50)
                        b[j+k] += a[k];
                }
            }
            for (int j = 0; j <= 50; j++)
                a[j] = b[j];
        }
        long long ans = 0;
        for (int i = 1; i <= 50; i++)
            ans += a[i];
        cout << ans << endl;
    }
    return 0;
}

你可能感兴趣的:(HDU2082(母函数))