题干:

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

题目大意:

给出比赛时间和题目数,并给出每道题目的耗时以及获得的价值,求所能获得的最大价值,以及获得这个最大价值下的最多题目数以及该情况的最小最少罚时(罚时为每道题目提交的时间之和)。

解题报告:

首先将这个时间序列问题转化成背包问题,然后考虑:假设最终选定了这些题目,那么最终价值和解题数都是一定的,但是为了得到最小罚时,我们需要贪心先做时间最短的题目,所以我们不妨先按照时间顺序排序。这样就不需要记录最终选择了哪些题了。(否则需要记录选择了哪些题目,然后再排序求ans3,十分不划算)

然后就是01背包,背包的同时维护这三个信息。

刚开始总是想着两次背包,先背出最大价值,然后再背包出最优解题数,同时维护ans3,,。。反正是WA了、、

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
const int MAX = 2e5 + 5;
int n,T;
struct Node {ll val,t;
} node[MAX];
struct N {ll val,num,t;N(){}N(ll val,ll num,ll t):val(val),num(num),t(t){}bool operator<(const N b)const{if(val != b.val) return val < b.val;if(num != b.num) return num < b.num;return t > b.t;}
} dp[MAX];
bool cmp(Node a,Node b) {return a.t < b.t;
}
int main()
{int t;cin>>t;while(t--) {scanf("%d%d",&T,&n);memset(dp,0,sizeof dp);for(int i = 1; i<=n; i++) scanf("%lld",&node[i].t);for(int i = 1; i<=n; i++) scanf("%lld",&node[i].val);sort(node+1,node+n+1,cmp);N ans = N(0,0,0);for(int i = 1; i<=n; i++) {for(int j = T; j>=node[i].t; j--) {N pre = dp[j-node[i].t];N tmp = N(pre.val + node[i].val,pre.num + 1,pre.t + j);if(dp[j] < tmp) dp[j] = tmp;if(ans < dp[j]) ans = dp[j];}}printf("%lld %lld %lld\n",ans.val,ans.num,ans.t);}return 0 ;
}

【ZOJ - 3703】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. 2015 German Collegiate Programming Contest (GCPC 15)

    2015 German Collegiate Programming Contest (GCPC 15) B. Bounty Hunter II 给定一张DAG,求一种方案:用最少的路径将所有点覆盖. ...

  4. Sichuan University Programming Contest 2018 Preliminary

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

  5. 2015 HIAST Collegiate Programming Contest J

    Polygons Intersection 题意:给2个凸多边形,求相交面积 思路:不会,套板子就是了 AC代码: #include "iostream" #include &qu ...

  6. (寒假开黑gym)2017-2018 ACM-ICPC German Collegiate Programming Contest (GCPC 2017)

    layout: post title: (寒假开黑gym)2017-2018 ACM-ICPC German Collegiate Programming Contest (GCPC 2017) au ...

  7. The 15th UESTC Programming Contest Preliminary C - C0ins cdoj1554

    地址:http://acm.uestc.edu.cn/#/problem/show/1554 题目: C0ins Time Limit: 3000/1000MS (Java/Others)     M ...

  8. 【AtCoder】diverta 2019 Programming Contest 2

    diverta 2019 Programming Contest 2 A - Ball Distribution 特判一下一个人的,否则是\(N - (K - 1) - 1\) #include &l ...

  9. 2018 German Collegiate Programming Contest (GCPC 18)

    2018 German Collegiate Programming Contest (GCPC 18) Attack on Alpha-Zet 建树,求lca 代码: #include <al ...

最新文章

  1. WCF 4.0 REST Service JSON跨域调用
  2. 2015年十佳IDC评选结果:50强名单揭晓
  3. [缓存]迅雷(XUNLEI)的工作原理揭密
  4. 选化学可否报计算机专业,选课选物化生报什么专业前景好
  5. 怎样把一个项目加入微服务器,构建微服务:快速搭建Spring Boot项目
  6. linux常用命令(2)常用系统工作命令
  7. [SDOI2009]学校食堂(状态压缩)
  8. SpringMVC中向服务器传输数据(解决get、post、delete、put请求乱码问题)
  9. Guice学习(一)
  10. 大数据预测实战-随机森林预测实战(三)-数据与特征对模型的影响
  11. 简单poi创建execl
  12. spring mvc 4.3.2 + mybatis 3.4.1 + mysql 5.7.14 +shiro 幼儿园收费系统 之 消息管理
  13. 反编译工具Reflector下载(转)
  14. 使用WangEditor编辑器使用图片上传功能
  15. String的intern()方法详解
  16. 【油猴脚本编写初体验】一键复制网页标题和地址(copy-title-and-location)
  17. Servlet与表单、数据库综合项目实战【学生信息管理】
  18. 用PHOTOSHOP 1寸照片制作方法
  19. Python爬虫练习:爬取猫眼电影实时票房
  20. UOS怎么改hyper-v虚拟机分辨率

热门文章

  1. [高效时间管理] 番茄工作钟 windows版本
  2. php html登陆逻辑,保持演示文稿(HTML)和逻辑(PHP)分开
  3. Mysql数据库---约束类型_mysql数据库的数据类型及约束
  4. 2-10 [搞定!]出栈序列的合法性 (20 分)
  5. bigdecimal 小于等于0_半场0-0比分的比赛,你需要注意这些
  6. linux 固定ip_linux固定IP
  7. rt5350 中断初始化
  8. wince下Gpio 驱动程序
  9. Idea报错,但是项目可以正常启动运行
  10. 计算机应用基础 第三版 实验报告,计算机应用基础实验报告(windows).doc