10130 - SuperSale
来源:互联网 发布:推广必备软件 编辑:程序博客网 时间:2024/04/25 09:30
SuperSale
There is a SuperSale in a SuperHiperMarket.Every person can take only one object of each kind, i.e. one TV, one carrot,but for extra low price. We are going with a whole family to that SuperHiperMarket.Every person can take as many objects, as he/she can carry out from the SuperSale.We have given list of objects with prices and their weight. We also know, whatis the maximum weight that every person can stand. What is the maximal value ofobjects we can buy at SuperSale?
Input Specification
The inputconsists of T test cases. The number of them (1<=T<=1000)is given on the first line of the input file.
Each testcase begins with a line containing a single integer number N thatindicates the number of objects (1 <= N <= 1000). Then followsN lines, each containing two integers: P and W. The first integer (1<=P<=100)corresponds to the price of object. The second integer (1<=W<=30) corresponds to the weight of object. Nextline contains one integer (1<=G<=100) it’s the number of people in our group. Next G lines contains maximalweight (1<=MW<=30) that can stand this i-th person from our family(1<=i<=G).
Output Specification
For everytest case your program has to determine one integer. Print out the maximalvalue of goods which we can buy with that family.
Sample Input
2
3
72 17
44 23
31 24
1
26
6
64 26
85 22
52 4
99 18
39 13
54 9
4
23
20
20
26
Output for the Sample Input
72
514#include<stdio.h>#include<string.h>struct data{int p;int w;}p[1005];int d[1005][35],r[105],t,n,g,i,j,k;;int main(){scanf("%d",&t);while(t--){int ans=0;scanf("%d",&n);for(i=1;i<=n;i++)scanf("%d%d",&p[i].p,&p[i].w);scanf("%d",&g);for(i=1;i<=g;i++)scanf("%d",&r[i]);memset(d,0,sizeof(d));for(k=1;k<=g;k++){for(i=1;i<=n;i++)for(j=1;j<=r[k];j++)if(j<p[i].w)d[i][j]=d[i-1][j];elsed[i][j]=(d[i-1][j]>(d[i-1][j-p[i].w]+p[i].p))?d[i-1][j]:(d[i-1][j-p[i].w]+p[i].p);ans+=d[n][r[k]];}printf("%d\n",ans);}return 0;}
- 10130SuperSale
- 10130 - SuperSale
- 10130 - SuperSale
- uva 10130 SuperSale
- UVA 10130 SuperSale
- Uva 10130 - SuperSale
- UVa 10130 - SuperSale
- UVa 10130 - SuperSale
- UVa 10130 - SuperSale 背包
- uva 10130 - SuperSale
- UVa 10130 - SuperSale
- UVa 10130 - SuperSale
- Uva-10130-SuperSale
- UVa:10130 SuperSale
- UVA - 10130 SuperSale
- UVa 10130 - SuperSale
- UVa 10130 - SuperSale
- uva 10130 SuperSale
- 第十一次试验任务
- “结巴”分词:做最好的Python分词组件
- Struts 2.x 实现防止表单重复提交
- uva 536Tree Recovery
- DIV CSS display (block none inline)属性的用法教程
- 10130 - SuperSale
- Oracle Error 查看网站
- display:inline、block、inline-block的区别
- js 正则总结
- apktool+dex2jar+xjad反编译APK文件
- EKF/UKF/IMM
- 黑马训练营——多线程之创建线程
- SQL触发器基础
- C#递归求解Factorial数列