博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
zoj 3703(背包)
阅读量:4674 次
发布时间:2019-06-09

本文共 4124 字,大约阅读时间需要 13 分钟。

简单的背包问题, 算是一种多重的吧。

解题的关键在于,要控制最后所用的时间最少,所以在程序的最开始应该先将 输入的各种题目 以时间升序排列, 然后就可以保证每次都以时间小的优先选, 这样就可以保证最后相同的吸引值和解题数的情况下所话的时间最少。

 

Happy Programming Contest

Time Limit: 2 Seconds     
 
Memory Limit: 65536 KB

In Zhejiang University Programming Contest, a team is called "couple team" if it consists of only two students loving each other. In the contest, the team will get a lovely balloon with unique color for each problem they solved. Since the girl would prefer pink balloon rather than black balloon, each color is assigned a value to measure its attractiveness. Usually, the boy is good at programming while the girl is charming. The boy wishes to solve problems as many as possible. However, the girl cares more about the lovely balloons. Of course, the boy's primary goal is to make the girl happy rather than win a prize in the contest.

Suppose for each problem, the boy already knows how much time he needs to solve it. Please help him make a plan to solve these problems in strategic order so that he can maximize the total attractiveness value of balloons they get before the contest ends. Under this condition, he wants to solve problems as many as possible. If there are many ways to achieve this goal, he needs to minimize the total penalty time. The penalty time of a problem is equal to the submission time of the correct solution. We assume that the boy is so clever that he always submit the correct solution.

Input

The first line of input is an integer N (N < 50) indicating the number of test cases. For each case, first there is a line containing 2 integers T (T <= 1000) and n (n <= 50) indicating the contest length and the number of problems. The next line contains n integers and the i-th integer ti (ti <= 1000) represents the time needed to solve the ith problem. Finally, there is another line containing n integers and the i-th integer vi (vi <= 1000) represents the attractiveness value of the i-th problem. Time is measured in minutes.

Output

For each case, output a single line containing 3 integers in this order: the total attractiveness value, the number of problems solved, the total penalty time. The 3 integers should be separated by a space.

Sample Input

2300 1010 10 10 10 10 10 10 10 10 101 2 3 4 5 6 7 8 9 10300 10301 301 301 301 301 301 301 301 301 3011000 1000 1000 1000 1000 1000 1000 1000 1000 1000

Sample Output

55 10 5500 0 0

Author: HUANG, Qiao
Contest: The 13th Zhejiang University Programming Contest

 

 

#include 
#include
#include
#include
using namespace std;struct node{ int key,time,cnt; int ty;}dp[1100][1100];struct node1{ int w,key;}g[1100];int t,n;int cmp(node1 t,node1 t1){ return t.w < t1.w;}int main(){ int T; scanf("%d",&T); while(T--) { scanf("%d%d",&t,&n); for(int i=1;i<=n;i++) scanf("%d",&g[i].w); for(int i=1;i<=n;i++) scanf("%d",&g[i].key); sort(g+1,g+1+n,cmp); memset(dp,0,sizeof(dp)); for(int i=1;i<=n;i++) { for(int j=0;j<=t;j++) { dp[i][j] = dp[i-1][j]; //dp[i][j].ty=j; if(j
dp[i][j].key ) { dp[i][j].cnt=tcnt; dp[i][j].key=tkey; dp[i][j].ty=j-g[i].w; dp[i][j].time=dp[i-1][j-g[i].w].time+j; continue; } // 如果解题数都相同的话 if(tcnt < dp[i][j].cnt) continue; if(tcnt>dp[i][j].cnt) { dp[i][j].cnt=tcnt; dp[i][j].ty=j-g[i].w; dp[i][j].time=dp[i-1][j-g[i].w].time+j; continue; } } } int mx=0,mxcnt=0,mxi=0; for(int i=0;i<=t;i++) { if(dp[n][i].key
mx) { mx=dp[n][i].key; mxcnt=dp[n][i].cnt; mxi=dp[n][i].time; continue; } if(dp[n][i].cnt
mxcnt) { mxcnt=dp[n][i].cnt; mxi=dp[n][i].time; continue; } if(dp[n][i].time

 

 

 

转载于:https://www.cnblogs.com/chenhuan001/archive/2013/04/22/3035091.html

你可能感兴趣的文章
Python自然语言处理学习笔记(41):5.2 标注语料库
查看>>
山寨“饿了么”应用中添加菜品数量按钮效果
查看>>
TCP/IP系列——长连接与短连接的区别
查看>>
Linux基础——常用命令
查看>>
Python学习笔记三(文件操作、函数)
查看>>
二进制分组
查看>>
[ACM] POJ 1068 Parencodings(模拟)
查看>>
Drools只执行一个规则或者执行完当前规则之后不再执行其他规则(转)
查看>>
20180110小测
查看>>
冰点还原8.57 官方中文版下载
查看>>
poj 2236(并查集的应用)
查看>>
C 栈 链式存储
查看>>
Java 游戏报错 看不懂求教
查看>>
APP自动化测试
查看>>
HTML中让表单input等文本框为只读不可编辑的方法
查看>>
nodejs做中间层,向后端取数据
查看>>
IntelliJ IDEA 2017 MySQL5 绿色版 Spring 4 Mybatis 3 配置步骤详解(二)
查看>>
(转)Java DecimalFormat 用法(数字格式化)
查看>>
hiho_100_八数码
查看>>
Eclipse序列号生成代码
查看>>