*【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

题目大意:

给出比赛时间和题目数,并给出每道题目的耗时以及获得的价值,找出所能获得的最大价值,获得这个最大价值下的最多题目数以及最少罚时,这里的罚时理解的半天,举第一个例子:A掉第一道题需要用时10分钟,然后第二道题也需要10分钟,即第二道题得在20分钟的时候A掉,所以两道题的罚时是10+20。

解题报告:

  直接用他给定的优先级就行了,按照优先级排序然后按照这个优先级顺序进行重载小于号然后做背包就行了。好题一只。

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/440173.shtml

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

相关文章

图解算法学习笔记(四):快速排序

目录 1&#xff09; 示例1&#xff1a; 2&#xff09;快速排序 3) 再谈大O表示法 4&#xff09;小结 本章内容&#xff1a;学习分而治之&#xff0c;快速排序 1&#xff09; 示例1&#xff1a; 假设你是农场主&#xff0c;有一小块土地&#xff0c;你要将这块地均匀分成方…

ThriftParserError: ThriftPy does not support generating module with path in protocol 'd'

使用python连接hive&#xff0c;在 from impala.dbapi import connect 语句报如下错误&#xff1a; ThriftParserError: ThriftPy does not support generating module with path in protocol d 定位到 D:\Anaconda3\Lib\site-packages\thriftpy\parser\parser.py的 if u…

【HDU - 5468】Puzzled Elena(容斥原理,dfs序,数学,素因子分解,有坑)

题干&#xff1a; Problem Description Since both Stefan and Damon fell in love with Elena, and it was really difficult for her to choose. Bonnie, her best friend, suggested her to throw a question to them, and she would choose the one who can solve it.Suppo…

图解算法学习笔记(五):散列表

目录 1&#xff09;示例1&#xff1a; 2&#xff09;散列函数 3&#xff09;应用案例 4&#xff09;冲突 5&#xff09;性能 6&#xff09;小结 本章内容&#xff1a; 学习散列表&#xff0c;最有用的数据结构之一。 学习散列表的内部机制&#xff1a;实现、冲突和散列函…

Ros 消息结构1

1、ROS的消息头信息 #Standard metadata for higher-level flow data types #sequence ID: consecutively increasing ID uint32 seq#Two-integer timestamp that is expressed as: # * stamp.secs: seconds (stamp_secs) since epoch # * stamp.nsecs: nanoseconds since sta…

【HDU - 5475】An easy problem(线段树,思维)

题干&#xff1a; One day, a useless calculator was being built by Kuros. Lets assume that number X is showed on the screen of calculator. At first, X 1. This calculator only supports two types of operation. 1. multiply X with a number. 2. divide X with…

图解算法学习笔记(六):广度优先搜索

目录 1&#xff09;图简介 2&#xff09;图是什么 3&#xff09;广度优先搜索 4&#xff09;实现图 5&#xff09;实现算法 6&#xff09;小结 本章内容; 学习使用新的数据结构图来建立网络模型&#xff1b; 学习广度优先搜索&#xff1b; 学习有向图和无向图…

图解算法学习笔记(七):狄克斯特拉算法

目录 1&#xff09;使用狄克斯特拉算法 2&#xff09;术语 3&#xff09;实现 4&#xff09;小结 本章内容; 介绍加权图&#xff0c;提高或降低某些边的权重&#xff1b; 介绍狄克斯特拉算法&#xff0c;找出加权图中前往X的最短路径&#xff1b; 介绍图中的环…

【HDU - 5477】A Sweet Journey(思维,水题)

题干&#xff1a; Master Di plans to take his girlfriend for a travel by bike. Their journey, which can be seen as a line segment of length L, is a road of swamps and flats. In the swamp, it takes A point strengths per meter for Master Di to ride; In the f…

[转载]Bluetooth协议栈学习之SDP

原文地址&#xff1a;Bluetooth协议栈学习之SDP作者&#xff1a;BigSam78作者&#xff1a; Sam &#xff08;甄峰&#xff09; sam_codehotmail.com SDP(service discovery protocol&#xff1a;服务发现协议)提供了一个方法&#xff0c;让应用程序检测哪些服务是可用的并探测这…

图解算法学习笔记(八):贪婪算法

目录 &#xff08;1&#xff09;背包问题 &#xff08;2&#xff09;集合覆盖问题 &#xff08;3&#xff09;NP完全问题 &#xff08;4&#xff09;小结 本章内容&#xff1a; 学习如何处理没有快速算法的问题&#xff08;NP完全问题&#xff09;。学习近似算法&#xff…

【CodeForces - 1152C 】Neko does Maths(数学数论,lcm,gcd性质)

题干&#xff1a; 给出a,b<1e9&#xff0c;你要找到最小的k使得lcm(ak,bk)尽可能小&#xff0c;如果有多个k给出同样的最小公倍数&#xff0c;输出最小的一个k。 解题报告&#xff1a; 因为题目中k太多了&#xff0c;先化简一下公式&#xff0c;假设a>b &#xff0c;则…

vs visual studio 2015安装后的几个问题

前言 最近在win7下重新安装了visual studio 2015&#xff0c;没有安装在默认路径下&#xff0c;编译时出现不少问题&#xff0c;整理如下 1.Failed to locate: "CL.exe". The system cannot find the file specified. TRACKER : error TRK0005: Failed to locate: “…

图解算法学习笔记(九):动态规划

目录 &#xff08;1&#xff09;背包问题 &#xff08;2&#xff09;最长公共子串 &#xff08;3&#xff09;小结 本章内容&#xff1a; 学习动态规划&#xff0c;它将问题分成小问题&#xff0c;并先着手解决这些小问题。学习如何设计问题的动态规划解决方案。 &#xff…

Java(win10安装jdk,第一个hello world)

Java 第一步 &#xff1a;安装jdk 推荐默认安装。&#xff08;安装到C盘&#xff09;第二步 &#xff1a;配置jdk环境 JAVA_HOME C:\Program Files\Java\jdk1.8.0_191 JDK的安装路径 Path&#xff1a; C:\Program Files\Java\jdk1.8.0_191\bin JDK下bin目录的路径 &#xf…

【POJ - 3177】Redundant Paths(边双连通分量,去重边)

题干&#xff1a; In order to get from one of the F (1 < F < 5,000) grazing fields (which are numbered 1..F) to another field, Bessie and the rest of the herd are forced to cross near the Tree of Rotten Apples. The cows are now tired of often being f…

#pragma 详解

#pragma 求助编辑 pragma - 必应词典美[prɡmə]英[prɡmə]n.〔计〕杂注网络编译指示&#xff1b;显示编译指示&#xff1b;特殊指令 百科名片 在所有的预处理指令中&#xff0c;#Pragma 指令可能是最复杂的了&#xff0c;它的作用是设定编译器的状态或者是指示编译器完成一些…

1.绪论

目录 &#xff08;1&#xff09;C语言传值与传地址变量 &#xff08;2&#xff09;算法效率的度量 &#xff08;3&#xff09;基本操作 &#xff08;4&#xff09;主函数 主要由实现基本操作和算法的程序构成。这些程序有6类&#xff1a; 数据存储结构&#xff0c;文件名第…

Java 新手习题()

循环 1.&#xff08;for 循环&#xff09;计算123…100 的和 package com.fxm.day03.test; public class day03test1{public static void main(String[] args){int sum 0;for(int i 1; i < 101; i){sum i;}System.out.println("1到100的和&#xff1a;"sum);…

(ECC)椭圆曲线加密算法原理和C++实现源码

目录 &#xff08;1&#xff09;ECC加密原理&#xff1a; &#xff08;2&#xff09;编译生成LibTommath静态库 &#xff08;3&#xff09;ECC源码 今天介绍一下利用LibTommath数学库实现椭圆曲线加密算法的原理和源码。 &#xff08;1&#xff09;ECC加密原理&#xff1a;…