hdu 2191 멀 티 백 팩 전 01 백 팩

http://acm.hdu.edu.cn/showproblem.php?pid=2191
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
const int MAX=101;
int DP[MAX];
using namespace std;
typedef struct rice
{
    int value;
    int weight;
    int num;
};
rice s[MAX];
int Max(int x,int y)
{
    return x>y?x:y;
}
int main()
{
    int t,n,m,i,j;
    cin>>t;
    while(t--)
    {
        cin>>n>>m;
        for(i=1;i<=m;i++)
        cin>>s[i].value>>s[i].weight>>s[i].num;
        memset(DP,0,sizeof(DP));
        for(i=1;i<=m;i++)
        {
            for(j=1;j<=s[i].num;j++)
            {
                for(int k=n;k>=s[i].value;k--)
                {
                    DP[k]=Max(DP[k],DP[k-s[i].value]+s[i].weight);
                }
            }
        }
        cout<<DP[n]<<endl;
    }
    return 0;
}

좋은 웹페이지 즐겨찾기