关闭

hduj 1114 完全背包

标签: include
344人阅读 评论(0) 收藏 举报
分类:
#include <iostream>
using namespace std;
 
int nCases;
int nPack, nVolume1, nVolume2, nVolume;
int weight[510], value[510];
int record[10000];
const int INF = 1000000001;
int main()
{    
   
 
    scanf("%d", &nCases);
    while(nCases--)
    {
        scanf("%d %d", &nVolume1, &nVolume2);
        nVolume = nVolume2-nVolume1;
        scanf("%d", &nPack);
        for(int i=0; i<nPack; ++i)
        {
            scanf("%d %d", &value[i], &weight[i]);
        }
        for(int i=0; i<=nVolume; ++i)
            record[i] = INF;
        record[0] = 0;
        for(int i=0; i<nPack; ++i)
            for(int j=weight[i]; j<=nVolume; ++j)
                if(record[j]>record[j-weight[i]]+value[i])
                    record[j] = record[j-weight[i]]+value[i];
        if(record[nVolume] == INF)
            printf("This is impossible.\n");
        else
            printf("The minimum amount of money in the piggy-bank is %d.\n",record[nVolume]);
 
    }
    return 0;
} 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:124701次
    • 积分:2361
    • 等级:
    • 排名:第16285名
    • 原创:115篇
    • 转载:11篇
    • 译文:3篇
    • 评论:13条
    常用链接
    最新评论