01背包(阴阳师)

#include <bits/stdc++.h>
using namespace std;
int dp[1005],f[1005];
int main(){
    ios::sync_with_sidio(false);
    int t;
    cin >>t;
    while(t--){
        memset(dp,0,sizeof(dp));
        int n,m;
        cin >> n >>m;
        int ans = 0;
        for(int i = 0;i <n;i ++){
            int w[1005],v[1005];
            int a;
            memcpy(f,dp,sizeof(f));
            cin >> a;
            for(int j = 0;j < a;j ++) cin >> v[j];
            for(int j = 0;j < a;j ++) cin >> w[j];
            for(int j = 0;j < a;j ++)
                for(int k=m; k>=w[j]; k--)
                    f[k]=max(f[k],dp[k-w[j]]+v[j]);//这里的比较很关键,决定了每种模式只选一个操作。
            memcpy(dp,f,sizeof(dp));
            /*for(int j = 0;j <= m;j ++)
            {
                cout<<dp[j]<<' ';
             } 
             cout<<endl;*/
        }
        cout<<dp[m]<<endl;
    }
    return 0;
}
作者:LightAc
出处:https://www.cnblogs.com/lightac/
联系:
Email: dzz@stu.ouc.edu.cn
QQ: 1171613053
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利。
原文地址:https://www.cnblogs.com/lightac/p/10747490.html