完全背包- Piggy-Bank
来源:互联网 发布:360手机解压缩软件 编辑:程序博客网 时间:2024/04/20 09:02
Description
Before ACM can do anything, a budget must be prepared and the necessary financial support obtained. The main income for this action comes from Irreversibly Bound Money (IBM). The idea behind is simple. Whenever some ACM member has any small money, he takes all the coins and throws them into a piggy-bank. You know that this process is irreversible, the coins cannot be removed without breaking the pig. After a sufficiently long time, there should be enough cash in the piggy-bank to pay everything that needs to be paid.
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.
本题就是一个完全背包问题,代码如下:
#include<stdio.h>#define MAX 9999999int dp[10005];int wi[501],vi[501];int main(){ int i,j,m,e,f,n,t; scanf("%d",&t); while(t--) { scanf("%d%d%d",&e,&f,&n); m=f-e; for(i=1;i<=m;i++) dp[i]=MAX; dp[0]=0; for(i=1;i<=n;i++) scanf("%d%d",&vi[i],&wi[i]); for(i=1;i<=n;i++) for(j=wi[i];j<=m;j++) dp[j]=dp[j]<dp[j-wi[i]]+vi[i]?dp[j]:dp[j-wi[i]]+vi[i]; if(dp[m]==MAX) printf("This is impossible.\n"); else printf("The minimum amount of money in the piggy-bank is %d.\n",dp[m]); } return 0;}
- 完全背包- Piggy-Bank
- Piggy-Bank(完全背包)
- 完全背包,piggy-bank
- Piggy-Bank (完全背包)
- Piggy-Bank完全背包
- 【完全背包】Piggy - Bank
- Piggy-Bank(完全背包)
- hdu1114 Piggy-Bank 完全背包
- Piggy-Bank(完全背包)
- Piggy-Bank hdu1114 完全背包
- Piggy-Bank 完全背包问题
- HD Piggy-Bank完全背包
- hdu1114 Piggy-Bank (完全背包)
- hdu-Piggy-Bank(完全背包)
- poj1384 Piggy-Bank(完全背包)
- HDU1114 Piggy-Bank 完全背包
- hdu1114 Piggy-Bank 完全背包
- HDU1114 Piggy-Bank 【完全背包】
- 素数环 南工488
- Dijkstra算法总结
- strlen和sizeof的区别
- S5PV210(TQ210)学习笔记——Nand flash驱动编写
- 奋斗黑马程序员----Java之泛型小结
- 完全背包- Piggy-Bank
- 一种基于CAS的无锁并发HashTable设计及C代码实现
- 学习日记-js基础
- 用指针访问对象
- 收集了点素数的判断方法。。。以备不时之需
- 链表的综合练习:增、删、改、查
- 【Linux】shell: 获取时间间隔到毫秒、微秒级别
- 正则表达式笔记1
- 二叉树层次遍历