HDU 2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活

题目:http://acm.hdu.edu.cn/showproblem.php?pid=2191

#include <iostream>
using namespace std;
int main(int argc, const char *argv[])
{
    int T;
    //freopen("input.txt","r",stdin);
    while(cin>>T)
    {
        while(T--)
        {
            int money,type;
            int dp[124]={0};
            memset(dp,0,sizeof(dp));
            cin>>money>>type;
            for(int i=0;i<type;i++)
            {
                int price,weight,num;
                cin>>price>>weight>>num;
                for(int k=1;k<=num;k++)
                    for(int j= money;j>=price*k;j--)
                    {
                        int t = dp[j-price]+weight;
                        dp[j]=dp[j]>t?dp[j]:t;
                        //printf("%d钱可获得最大容量%d\n",j,dp[j]);
                    }
            }
            cout<<dp[money]<<endl;
        }
    }
    return 0;
}

 

posted @ 2013-09-21 21:48  Destino74  阅读(167)  评论(0编辑  收藏  举报