light oj 1231 dp 多重背包

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <climits>
#include <queue>
#define ll long long

using namespace std;

const int MOD = 1e8+7;

int dp[55][1010];

void solve()
{
    int n,k,w[1005],cnt[1005];
    scanf("%d %d",&n,&k);
    memset(dp,0,sizeof(dp));
    for(int i = 1; i <= n; i++)
        scanf("%d",&w[i]);
    for(int i = 1; i <= n ;i++)
        scanf("%d",&cnt[i]);
    dp[0][0] = 1;
    for(int i = 1; i <= n; i++)
    {
        for(int j = 0; j <= cnt[i]; j++)
            for(int m = j*w[i]; m <= k; m++)
                dp[i][m] = (dp[i][m]+dp[i-1][m - j*w[i]])%MOD;
    }
    printf("%d\n",dp[n][k]);
}

int  main(void)
{
    int t,cnt = 0;
    scanf("%d",&t);
    while(t--)
    {
        printf("Case %d: ",++cnt);
        solve();
    }
    return 0;
}

posted on 2016-08-13 18:21  鱼泪儿  阅读(101)  评论(0编辑  收藏  举报

导航