Light oj 1200 - Thief(水)
2015-09-27 21:45
183 查看
1200 - Thief
A thief has entered into a super shop at midnight. Poor thief came here because his wife has sent him to buy some necessary households. Instead of buying the items, he decided to steal them.
He has a bag with him which can carry up to W kg. In the list (given by his wife) there are four fields 1) item name, 2) the price of the item, 3) how many of this item is required and 4) the weight of this item. The items are solid items,
so he can't take any item after dividing into pieces.
Now the thief wants to take items in his bag such that it fulfills his wife's list, and the total weight of the items is not greater than W. And he can't take any item other than the items mentioned in the list, otherwise his wife would
found the item and he may get caught. But he can take more items than required. And he wants to sell these extra items and earn some money. Assume that he can take any item (is in the list) any number of times unless they overflow his bag.
Now you are given the necessary information of the items and his bag, you have to find the maximum profit the thief can make.
Each case starts with a line containing two integers n (1 ≤ n ≤ 100) and W (1 ≤ W ≤ 10000), where n denotes the number of items. Each of the next n lines contains three integers pi ci wi (1
≤ pi, ci, wi ≤ 100), meaning that the price of the ith item is pi, ci of it must be taken, and the weight is wi.
PROBLEM SETTER: JANE ALAM JAN
PDF (English) | Statistics | Forum |
Time Limit: 3 second(s) | Memory Limit: 32 MB |
He has a bag with him which can carry up to W kg. In the list (given by his wife) there are four fields 1) item name, 2) the price of the item, 3) how many of this item is required and 4) the weight of this item. The items are solid items,
so he can't take any item after dividing into pieces.
Now the thief wants to take items in his bag such that it fulfills his wife's list, and the total weight of the items is not greater than W. And he can't take any item other than the items mentioned in the list, otherwise his wife would
found the item and he may get caught. But he can take more items than required. And he wants to sell these extra items and earn some money. Assume that he can take any item (is in the list) any number of times unless they overflow his bag.
Now you are given the necessary information of the items and his bag, you have to find the maximum profit the thief can make.
Input
Input starts with an integer T (≤ 100), denoting the number of test cases.Each case starts with a line containing two integers n (1 ≤ n ≤ 100) and W (1 ≤ W ≤ 10000), where n denotes the number of items. Each of the next n lines contains three integers pi ci wi (1
≤ pi, ci, wi ≤ 100), meaning that the price of the ith item is pi, ci of it must be taken, and the weight is wi.
Output
For each case, print the case number and the maximum profit he can get. If it's impossible to fulfill his wife's requirements, print 'Impossible'.Sample Input | Output for Sample Input |
2 3 20 10 1 10 5 1 5 1 1 1 1 10 10 1 11 | Case 1: 4 Case 2: Impossible |
#pragma comment(linker, "/STACK:1024000000,1024000000") #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<queue> #include<stack> #include<vector> #include<map> #define L(x) (x<<1) #define R(x) (x<<1|1) #define MID(x,y) ((x+y)>>1) #define bug printf("hihi\n") #define eps 1e-12 typedef long long ll; using namespace std; #define N 10005 int dp ,n,all; int price ,cost ; int main() { int i,j,t,ca=0; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&all); int temp=0; int x; for(i=0;i<n;i++) { scanf("%d%d%d",&price[i],&x,&cost[i]); temp+=x*cost[i]; } if(temp>all) { printf("Case %d: Impossible\n",++ca); continue; } all-=temp; memset(dp,0,sizeof(dp)); for(int i=0;i<n;i++) for(int v=cost[i];v<=all;v++) dp[v]=max(dp[v],dp[v-cost[i]]+price[i]); printf("Case %d: %d\n",++ca,dp[all]); } return 0; }
相关文章推荐
- Task(二维关键字不同且有向的贪心思想(有坑点,反向求会wa。。))
- VS的帮助MSDN出错,无法打开时的修复方法
- 数组指针解析
- SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource' 的访问
- OC和C头文件及打印输出区别
- 论JAVA项目对头脑的锻炼程度
- Mysql主从节点不同步解决方法
- sql中视图视图的作用
- jquery的一些学习心得总结
- Oracle 11g R2 For RedHat Enterprise Linux 6.3 安装说明书
- 工厂方法(Factory Method)模式
- 前端笔记
- C语言排序实例(选择、冒泡、插入、折半、快速)
- nasm : dump memory to file on bochsdbg
- 总结
- 中华人民共和国专利法
- Zero Downtime Upgrade of Oracle 10g to Oracle 11g Using GoldenGate — 2
- Linux基础学习2,Linux基本概念及操作,转载自实验楼
- 测试用例的设计方法
- vijos1739:计算系数