hdu 2079母涵数

简单,直接上代码

/*

 * hdu2079/win.cpp

 * Created on: 2012-8-2

 * Author    : ben

 */

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <ctime>

#include <iostream>

#include <algorithm>

#include <queue>

#include <set>

#include <map>

#include <stack>

#include <string>

#include <vector>

#include <deque>

#include <list>

#include <functional>

#include <numeric>

#include <cctype>

using namespace std;

const int MAXN = 10;

const int MAXV = 1000;

int scores[MAXN], nums[MAXN];

int res[MAXV], temp[MAXV];

int main() {

#ifndef ONLINE_JUDGE

    freopen("data.in", "r", stdin);

#endif

    int T, M, N;

    scanf("%d", &T);

    while(T--) {

        scanf("%d%d", &M, &N);

        for(int i = 0; i < N; i++) {

            scanf("%d%d", &scores[i], &nums[i]);

        }

        memset(res, 0, sizeof(res));

        for(int j = 0; j <= nums[0]; j++) {

            res[j * scores[0]] = 1;

        }

        for(int i = 1; i < N; i++) {

            memset(temp, 0, sizeof(temp));

            for(int j = 0; j <= nums[i]; j++) {

                int t = j * scores[i];

                for(int k = 0; k < MAXV; k++) {

                    if(res[k] > 0) {

                        temp[k + t] += res[k];

                    }

                }

            }

            memcpy(res, temp, sizeof(temp));

        }

        printf("%d\n", res[M]);

    }

    return 0;

}

你可能感兴趣的:(HDU)