ZOJ3703 Happy Programming Contest 2017-04-06 23:33 61人阅读 评论(0) 收藏
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
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
题目的意思是给出总时间和题目的数量,每道题有花费时间和价值,求价值最大是多少,价值最大不唯一时,按题目数量多的排,题目数量也一样按罚时少的排
思路:01背包,加上相等时判定的更新即可
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <cctype>
#include <sstream>
#include <climits> using namespace std; #define LL long long
const int INF=0x3f3f3f3f;
int mod=1e9+7; struct node{
int val,num,t,sum;
}dp[1005]; struct pro{
int w,v;
}p[100]; bool cmp(pro a,pro b)
{
if(a.w!=b.w)
return a.w<b.w;
return a.v>b.v;
} int main()
{
int T,m,n;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&m,&n);
for(int i=0;i<n;i++)
scanf("%d",&p[i].w);
for(int i=0;i<n;i++)
scanf("%d",&p[i].v); memset(dp,0,sizeof dp);
sort(p,p+n,cmp);
for(int i=0;i<n;i++)
{
for(int j=m;j>=p[i].w;j--)
{
if(dp[j].val<dp[j-p[i].w].val+p[i].v)
{
dp[j].val=dp[j-p[i].w].val+p[i].v;
dp[j].num=dp[j-p[i].w].num+1;
dp[j].t=dp[j-p[i].w].t+p[i].w;
dp[j].sum=dp[j-p[i].w].sum+dp[j].t;
}
else if(dp[j].val==dp[j-p[i].w].val+p[i].v)
{
if(dp[j].num<dp[j-p[i].w].num+1)
{
dp[j].num=dp[j-p[i].w].num+1;
dp[j].t=dp[j-p[i].w].t+p[i].w;
dp[j].sum=dp[j-p[i].w].sum+dp[j].t;
}
else if(dp[j].num==dp[j-p[i].w].num+1)
{
if(dp[j].sum>dp[j-p[i].w].sum+dp[j-p[i].w].t+p[i].w)
{
dp[j].t=dp[j-p[i].w].t+p[i].w;
dp[j].sum=dp[j-p[i].w].sum+dp[j].t;
}
}
}
}
}
printf("%d %d %d\n",dp[m].val,dp[m].num,dp[m].sum);
}
return 0;
}
ZOJ3703 Happy Programming Contest 2017-04-06 23:33 61人阅读 评论(0) 收藏的更多相关文章
- POJ3104 Drying 2017-05-09 23:33 41人阅读 评论(0) 收藏
Drying Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 15604 Accepted: 3976 Descripti ...
- HDU 2101 A + B Problem Too 分类: ACM 2015-06-16 23:57 18人阅读 评论(0) 收藏
A + B Problem Too Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- ZOJ2478 Encoding 2017-04-18 23:02 43人阅读 评论(0) 收藏
Encoding Time Limit: 2 Seconds Memory Limit: 65536 KB Given a string containing only 'A' - 'Z', ...
- 动态链接库(DLL) 分类: c/c++ 2015-01-04 23:30 423人阅读 评论(0) 收藏
动态链接库:我们经常把常用的代码制作成一个可执行模块供其他可执行文件调用,这样的模块称为链接库,分为动态链接库和静态链接库. 对于静态链接库,LIB包含具体实现代码且会被包含进EXE中,导致文件过大, ...
- NYOJ-235 zb的生日 AC 分类: NYOJ 2013-12-30 23:10 183人阅读 评论(0) 收藏
DFS算法: #include<stdio.h> #include<math.h> void find(int k,int w); int num[23]={0}; int m ...
- HDU 2034 人见人爱A-B 分类: ACM 2015-06-23 23:42 9人阅读 评论(0) 收藏
人见人爱A-B Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- HDU 2035 人见人爱A^B 分类: ACM 2015-06-22 23:54 9人阅读 评论(0) 收藏
人见人爱A^B Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- HDU2033 人见人爱A+B 分类: ACM 2015-06-21 23:05 13人阅读 评论(0) 收藏
人见人爱A+B Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- HDU4081 Qin Shi Huang's National Road System 2017-05-10 23:16 41人阅读 评论(0) 收藏
Qin Shi Huang's National Road System ...
随机推荐
- vue2.0实现一个模态弹框,内容自定义(使用slot)
定义模态框:合理使用插槽 model.vue <!-- 模态弹窗 --> <template> <div class="self-modal" v-s ...
- 代码规范 for node.js with 'npm-coding-style'
npm-coding-style npm's "funny" coding style Description npm's coding style is a bit unconv ...
- 微软开源rDSN分布式系统开发框架
摘要:微软亚洲研究院系统组开发的分布式系统开发框架——Robust Distributed System Nucleus(rDSN)正式在GitHub平台开源.据悉,rDSN是一个旨在为广大分布式系统 ...
- 腾讯高性能RPC开发框架Tars实现服务治理(微服务)
Github:https://github.com/Tencent/Tars 1. 介绍 Tars是基于名字服务使用Tars协议的高性能RPC开发框架,同时配套一体化的服务治理平台,帮助个人或者企业快 ...
- Web API 源码剖析之默认消息处理程序链--》路由分发器(HttpRoutingDispatcher)
我们在上一节讲述了默认的DefaultServer(是一个类型为HttpServer的只读属性,详情请参考 Web API 源码剖析之全局配置).本节将讲述DefaultHandler(是一个Http ...
- Ajax请求WCF服务以及跨域的问题解决
Ajax请求WCF服务以及跨域的问题解决 这两天准备重构一下项目,准备用纯html+js做前台,然后通过ajax+WCF的方式来传递数据,所以就先研究了一下ajax访问的wcf的问题,还想到还折腾了一 ...
- ImportError: Couldn't import Django.或者提示Django 模块不存在
ImportError: Couldn't import Django. 或者 多版本的python引起的,执行以下命令 即可解决问题 python3是新的版本的python python3 -m ...
- zmq消息订阅
一个需求,用户预约了手机超时没有使用,要通知到预约的用户“设备超时”. 我本来是自己这一端计时然后超时后推送通知的. 但是上海测说他那边计时,然后释放手机.我这边只要订阅他那边的消息就好了. 外部的应 ...
- 「小程序JAVA实战」小程序视频处理工具ffmpeg(47)
转自:https://idig8.com/2018/09/16/xiaochengxujavashizhanxiaochengxushipinchuligongjuffmpeg46/ 前面已经把视频成 ...
- AOP术语
1.连接点(Joinpoint) 程序执行的某个特定位置:如类开始初始化前,类初始化后,类某个方法调用前,调用后,方法跑出异常后.一个类或一段程序代码拥有一些具有边界性质的特定点.这些代码中的特定点就 ...