POJ 1384 完全背包
来源:互联网 发布:交换机有mac地址吗 编辑:程序博客网 时间:2024/05/20 17:07
如题:http://poj.org/problem?id=1384
Description
But there is a big problem with piggy-banks. It is not possible to determine how much money is inside. So we might break the pig into pieces only to find out that there is not enough money. Clearly, we want to avoid this unpleasant situation. The only possibility is to weigh the piggy-bank and try to guess how many coins are inside. Assume that we are able to determine the weight of the pig exactly and that we know the weights of all coins of a given currency. Then there is some minimum amount of money in the piggy-bank that we can guarantee. Your task is to find out this worst case and determine the minimum amount of cash inside the piggy-bank. We need your help. No more prematurely broken pigs!
Input
Output
Sample Input
310 11021 130 5010 11021 150 301 6210 320 4
Sample Output
The minimum amount of money in the piggy-bank is 60.The minimum amount of money in the piggy-bank is 100.This is impossible.
往存钱罐里装钱 要求钱最多的同时重量满的时候钱要最少(注意是最少) f[j]=min(f[j],f[j-c[i]]+w[i]);
完全背包问题
唯一需要注意的是重量上限是满时的重量-空时的重量
f数组初始全部最大 f【0】=0重量0时钱是0
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define min(a,b)(a<b?a:b)
int E,F;
int c[505];
int w[505];
int f[10005];
int main()
{
// freopen("C:\\1.txt","r",stdin);
int T,n;
cin>>T;
while(T--)
{
scanf("%d%d",&E,&F);
int w1=F-E;
scanf("%d",&n);
int i,j;
for(i=1;i<=n;i++)
scanf("%d%d",&w[i],&c[i]);
for(i=0;i<10005;i++)
f[i]=0x0fffffff;
f[0]=0;
for(i=1;i<=n;i++)
for(j=c[i];j<=w1;j++)
f[j]=min(f[j],f[j-c[i]]+w[i]);
if(f[w1]==0x0fffffff)
printf("This is impossible.\n");
else
printf("The minimum amount of money in the piggy-bank is %d.\n",f[w1]);
}
}
- POJ-1384 完全背包
- POJ 1384 完全背包
- poj 1384完全背包
- 完全背包 poj 1384
- poj 1384完全背包
- poj 1384 完全背包
- 完全背包 POJ 1384
- POJ 1384 完全背包
- POJ-1384 完全背包
- POJ 1384 【完全背包】
- POJ 1384【完全背包】
- poj 1384 完全背包
- poj 1384 完全背包问题
- POJ 1384 完全背包问题
- POJ 1384 完全背包问题
- poj 1384 Piggy-Bank 完全背包
- poj 1384Piggy-Bank(完全背包)
- POJ 1384 Piggy-Bank (完全背包)
- Android控件之ImageView
- xcode6中快捷键
- 1.Java NIO系列教程之概述
- unity学习之NGUI(二)
- 1011
- POJ 1384 完全背包
- Fibonacci Again
- 数据结构实验八——队列打印杨辉三角
- unity学习之NGUI(一)
- Running Python Programs from Emacs
- qplot()函数的详细用法
- 源码系列:红黑树
- 利用窗口分割将多EXE嵌入统一程序(MFC)
- Least Common Multiple