HDU1085(母函数)

也是比较水~

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define maxn 8111

long long a[maxn], b[maxn];
int n, num[11];
int c[11];

int main () {
    //freopen ("data.txt", "r", stdin);
    c[1] = 1, c[2] = 2, c[3] = 5;
    while (cin >> num[1] >> num[2] >> num[3]) {
        if (!num[1] && !num[2] && !num[3])
            break;
        memset (a, 0, sizeof a);
        int Max = num[1]+2*num[2]+5*num[3];
        for (int i = 0; i <= num[1]; i++)
            a[i] = 1;
        for (int i = 2; i <= 3; i++) {
            memset (b, 0, sizeof b);
            for (int j = 0; j <= c[i]*num[i]; j += c[i]) {
                for (int k = 0; k <= Max; k++) {
                    if (j+k <= Max)
                        b[j+k] += a[k];
                }
            }
            for (int j = 0; j <= Max; j++)
                a[j] = b[j];
        }
        for (int i = 1; i <= Max+1; i++)
        if (a[i] == 0) {
            cout << i << endl;
            break;
        }
    }
    return 0;
}


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