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
2
300 10
10 10 10 10 10 10 10 10 10 10
1 2 3 4 5 6 7 8 9 10
300 10
301 301 301 301 301 301 301 301 301 301
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000

Sample Output
55 10 550
0 0 0
题目链接
参考题解

  •  题目讲的是一对情侣在赛码场上,每道题对应不同颜色的气球,不同的气球对妹子的吸引力不同。在已知程序员做每道题所需的时间、比赛总时长以及每一个气球对妹子的吸引值。求在能力和时间允许的前提下,得到的气球对妹子吸引力的总值最大为多少。要求输出,吸引总值,解题数目,罚时。
  •  这个题目在做的时候,感觉跟背包很像,但是由于状态量很多,不知道应该怎么记录。赛后看了看题解,可以将遍历过程中的每一个状态用数组记录下来。开一个二维数组,第一维代表题目序号,第二维表示做完这个题目为止已经用了多少时间。数组内部存储0或1,代表有没有经历这个状态。这样,我们从后面往前遍历,也就是从最后一个题目往前遍历,只要这个状态经历过,那么就把这个题目放上,说明做完了,那么到最后取完一定能保证做的题目个数最多。然后再按照每道题目的花费时间排序,这样就能保证罚时最短了。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 1e3 + 10;
int f[maxn], G[55][maxn], t[55], v[55], ord[55];
int n, tt;int main()
{int T;cin >> T;while(T--){scanf("%d%d", &tt, &n);for(int i = 1; i <= n; i++) scanf("%d", &t[i]);for(int i = 1; i <= n; i++) scanf("%d", &v[i]);memset(f, 0, sizeof(f));memset(G, 0, sizeof(G));for(int i = 1; i <= n; i++){for(int j = tt; j >= t[i]; j--){if(f[j] < f[j - t[i]] + v[i]){f[j] = f[j - t[i]] + v[i];G[i][j] = 1;}}}int cnt = 0, i = n, j = tt;while(i){if(G[i][j] == 1){ord[cnt++] = t[i];j -= t[i];}i--;}int pently = 0, sum = 0;sort(ord, ord + cnt);for(int i = 0; i < cnt; i ++){sum += ord[i];pently += sum;}printf("%d %d %d\n", f[tt], cnt, pently);}return 0;
}

Happy Programming Contest(01背包)相关推荐

  1. ZOJ 3703 Happy Programming Contest 0-1背包 DP

    ZOJ 3703 Happy Programming Contest 题目描述: 题目链接:ZOJ 3703 Happy Programming Contest 题目大意: 这是一道虐狗的题目.讲的是 ...

  2. 【ZOJ - 3703】Happy Programming Contest(带优先级的01背包,贪心背包)

    题干: In Zhejiang University Programming Contest, a team is called "couple team" if it consi ...

  3. *【ZOJ - 3703】Happy Programming Contest(带优先级的01背包)

    题干: In Zhejiang University Programming Contest, a team is called "couple team" if it consi ...

  4. HDU 2546(01背包)

    饭卡 Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...

  5. HDU 2546 饭卡(01背包裸题)

    饭卡 Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...

  6. 01背包总结+传授个人经验

    写在前面: 自从学了背包这个专题,感觉永远也写不完,之前写了三种类型的01背包,结果现在发现都是简单的01背包.后来又学了多重背包.完全背包,其中多重背包还可以进行二进制优化. 本文将对这几种常见的背 ...

  7. Sichuan University Programming Contest 2018 Preliminary

    嗯为了防止大家AK,所以这次的A题和K题我们就当做不存在好了! 经历了昨天写了两个多小时的博客没保存的心态炸裂,今天终于下了个Markdown.所以我猜这篇的格式应该会更好看一点! 好吧废话不多说 题 ...

  8. HDU 2546 饭卡 01背包变形

    饭卡 Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...

  9. hdu 2546 饭卡(01背包)

    题意:只要最后留下的钱够5元,就可以买下最贵的食物,使得余额最低,其他的钱的使用就是一个最大背包问题了. 代码: #include<iostream> #include<cstrin ...

最新文章

  1. Ubuntu常用工具
  2. AS 4.7安装yum
  3. 镇海区工业机器人与自动化设备_工业机器人和工业自动化设备的区别
  4. 使用/proc/meminfo文件查看内存状态信息
  5. Java高并发编程详解系列-线程上下文设计模式及ThreadLocal详解
  6. 如何将word表结构转换为excel表格,最终转换为PowerDesigner格式
  7. RHEL 8 - 记录用户会话操作
  8. 本田da屏怎么进wince系统_谁说思域要停产的?打脸来得不是一般的快 第十一代本田思域Prototype...
  9. 织梦 html5视频显示问题,织梦网站HTML5 video视频播放器(不用安装插件)
  10. 数据结构与算法的实现 —— 结点定义与数据结构的选择
  11. java中string类的常用方法举例说明
  12. 手把手教你强化学习 (五) 为什么需要值迭代和策略迭代
  13. DOM操作简易年历案例
  14. 遍历目录 nftw and ftw
  15. 告别2018:人间值得,你更值得!
  16. 熟知四种常见的BIOS信息说明【7gyy】
  17. 攻读计算机应用在职研究生,在职研究生《计算机应用》复习资料.doc
  18. 2017南京理工大学计算机录取分数,2018南京理工大学录取分数线预估 2017录取分数线...
  19. 百度网盘加速无限试用_单次付费来了!免费试用后,百度网盘出现3元/5分钟延长加速下载...
  20. 外观模式--牛市股票还会亏钱

热门文章

  1. java 输入一个时间,获取当前周的周一以及周五时间【自然周】
  2. 计算机一级b类考试题软件,全国计算机等级考试一级b类windows模拟考题(二)
  3. java邮件发送代码报错_javamail发送附件不通过也不报错
  4. Matlab课后笔记之霍夫变换(Hough Transform)
  5. 度过漫长又艰辛的 2020 年,我收集了 1273 人的年度感悟
  6. 破晓传说Boss切屏效果小记
  7. mysql 导出指定分隔符_mysql 导出行数据到txt文件,指定字符分割
  8. 《剑魂之刃》游戏破解
  9. 心形线(Java语言实现) 原理与具体实现
  10. 不忘历史、维护中国海权