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

题干:

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 ;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/440639.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

固定 顶部_纹络型温室大棚顶部通风样式及效率对比

纹络型温室大棚是一种使用玻璃作为覆盖材料的温室大棚&#xff0c;该种温室大棚由于抗风雪能力强&#xff0c;环境控制能力强、使用年限长&#xff0c;目前在我国的南北地区大量建造。由于该型号的玻璃温室大棚单体占地面积能够达到几十亩地&#xff0c;因此单靠墙面通风无法满…

微型计算机智能体重评测,荣耀智能体脂秤WiFi版评测:17项身体指标 比你更懂你...

原标题&#xff1a;荣耀智能体脂秤WiFi版评测&#xff1a;17项身体指标 比你更懂你[PConline 评测]俗话说冬天不减肥&#xff0c;夏天徒伤悲&#xff0c;每个人都希望拥有穿衣显瘦、脱 衣有肉的完美身材。但往往理想很丰满&#xff0c;现实很骨感&#xff0c;很多人都陷入减肥的…

【ZOJ - 3211】Dream City (01背包类问题,贪心背包)

题干&#xff1a; JAVAMAN is visiting Dream City and he sees a yard of gold coin trees. There are n trees in the yard. Lets call them tree 1, tree 2 ...and tree n. At the first day, each tree i has ai coins on it (i1, 2, 3...n). Surprisingly, each tree i c…

gitlable iphone_使用gitlab ci构建IOS包并发送通知消息到企业微信

在之前的文章中&#xff0c;我们介绍了使用gitlab ci构建Android包的方法。今天我们介绍使用gitlab ci如何构建IOS包&#xff0c;并且在打包成功或者失败时&#xff0c;如何将消息通知到企业微信。如果对gitlab ci还不熟悉的&#xff0c;可以参考之前的文章使用gitlab ci构建An…

2020计算机网络基础与应用,2020年国防科技大学硕士研究生考试F1107计算机网络基础考试大纲...

全国各省市院校2020年硕士研究生考试大纲汇总(持续更新中)》》》2020年全国硕士研究生入学考试命题标准大纲已于7月8日正式公布&#xff0c;接下来全国各研招院校将陆续发布2020考研专业课大纲。以下是中公考研小编整理的“2020年国防科技大学硕士研究生考试F1107计算机网络基础…

【ZOJ - 3212 】K-Nice (构造)

题干&#xff1a; This is a super simple problem. The description is simple, the solution is simple. If you believe so, just read it on. Or if you dont, just pretend that you cant see this one. We say an element is inside a matrix if it has four neighbori…

chrome jsp 显示不正常_JSP程序在chrome下不兼容的问题!

比如&#xff0c;我这里有个&#xff1a;">比如&#xff0c;我这里有个&#xff1a;οnclick"javascript:onChooseLongCode()" value"...">在下面的JS动作中&#xff1a;function onChooseLongCode(){var qryFldVal qryFld.value;//要用 var q…

人脑意识转入量子计算机,人脑产生意识:可能是因为量子纠缠

图片来源&#xff1a;quanta magazine一提到“量子意识”这个词语&#xff0c;大多数物理学家都会选择避而不谈&#xff0c;因为这个词语听起来好像有点“民科”&#xff0c;甚至让人联想宗教或者玄学。不过出人意料的是&#xff0c;量子效应可能真的在人类的认知过程中起到了一…

【ZOJ - 1163】The Staircases(dp)

题干&#xff1a; One curious child has a set of N little bricks. From these bricks he builds different staircases. Staircase consists of steps of different sizes in a strictly descending order. It is not allowed for staircase to have steps equal sizes. Ev…

函授本科统考计算机考试时间,函授2006级计算机、机电本科第一学期考试时间安排.doc...

函授2006级计算机、机电本科第一学期考试时间安排.doc函授2006级计算机、机电本科第一学期考试时间安排答疑时间9月16日下午2&#xff1a;30&#xff0d;3&#xff1a;309月16日下午3&#xff1a;30&#xff0d;4&#xff1a;309月16日下午4&#xff1a;30&#xff0d;5&#x…

的级联选择_级联接收机的计算及Y因子噪声因子测量法

对于RF系统工程师来说&#xff0c;计算噪声系数预算对预测产品性能至关重要。一、级联接收机的计算这部分讨论噪声系数的一般概念&#xff0c;以及产品定义和电路设计者如何利用噪声系数表示噪声性能要求。噪声系数也用于预测接收机系统的总体灵敏度。也介绍级联接收机的噪声系…

*【PAT天梯】分而治之(并查集,暴力)

题干&#xff1a; L2-1 分而治之 &#xff08;25 分&#xff09; 分而治之&#xff0c;各个击破是兵家常用的策略之一。在战争中&#xff0c;我们希望首先攻下敌方的部分城市&#xff0c;使其剩余的城市变成孤立无援&#xff0c;然后再分头各个击破。为此参谋部提供了若干打击…

免费测试英语发音的软件,2020英语音标免费版

2020英语音标免费版是一款安卓手机英语音标内容学习软件&#xff0c;在这里汇集了英语音标相关内容学习&#xff0c;包含了音标、发音等内容学习&#xff0c;能够进行对比练习&#xff0c;不断对比&#xff0c;让发音更标准&#xff0c;拥有详细的发音知识可以学习&#xff0c;…

ajax后台重定向会返回什么_跳转,AJAX返回和重定向

## 页面跳转操作完成后,成功或失败页面跳转可以使用 控制器基类的success,error方法:#### success方法php/*** 操作成功跳转的快捷方法* access protected* param mixed $msg 提示信息* param string $url 跳转的URL地址* param mixed $data 返回的数据* param integer $wait 跳…

【PAT天梯】【L2-2 小字辈(左子右兄加强版)】(树,水题)

题干&#xff1a; L2-2 小字辈&#xff08;左子右兄加强版&#xff09; &#xff08;25 分&#xff09; 本题给定一个庞大家族的家谱&#xff0c;要请你给出最小一辈的名单。 需要注意的是&#xff0c;家族成员的输入方式&#xff0c;是按照“Left-child Right-sibling”&…

W10的服务器正在运行,win10开机提示服务器正在运行中的解决教程

今天小编给大家分享的是win10开机提示服务器正在运行中的解决教程。最近有win10的用户反映&#xff0c;在开机的时候莫名的就出现了个“服务器正在运行中”的气泡提示&#xff0c;出现此问题困扰的用户&#xff0c;请来看看下面的解决教程吧。使用win10系统过程中&#xff0c;在…

host ntrip 千寻rtk_最新测量干货:南方银河1和银河1Plus RTK设备连接千寻cors账号的设置方法...

无论刚接触网络RTK的测量员是想要进行华测RTK连接千寻cors账号的操作&#xff0c;还是中海达RTK连接千寻cors账号&#xff0c;亦或者司南RTK连接千寻cors账号的操作&#xff0c;我们在进行cors账号的连接操作之前都应该对操作的RTK设备有一个了解&#xff0c;所以今天我们在给大…

【CodeForces - 1084D】The Fair Nut and the Best Path (树形dp)

题干&#xff1a; The Fair Nut is going to travel to the Tree Country, in which there are nn cities. Most of the land of this country is covered by forest. Furthermore, the local road system forms a tree (connected graph without cycles). Nut wants to rent …

消息测试服务器,测试统一消息服务器功能

测试统一消息服务器功能08/07/2014本文内容适用于&#xff1a; Exchange Server 2007 SP1, Exchange Server 2007上一次修改主题&#xff1a; 2007-08-09在运行 Microsoft Exchange Server 2007 的计算机上安装统一消息服务器角色并启用和配置统一消息 (UM) 之后&#xff0c;可…

python不同曲线设置标签_【图像分类】基于Pascal VOC2012增强数据的多标签图像分类实战...

接着上一次的多标签分类综述&#xff0c;本文主要以Pascal VOC2012增强数据集进行多标签图像分类训练&#xff0c;详细介绍增强数据集制作、训练以及指标计算过程&#xff0c;并通过代码进行详细阐述&#xff0c;希望能为大家提供一定的帮助&#xff01;作者&编辑 | 郭冰洋…