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) 收藏的更多相关文章

  1. POJ3104 Drying 2017-05-09 23:33 41人阅读 评论(0) 收藏

    Drying Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 15604   Accepted: 3976 Descripti ...

  2. 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 ...

  3. 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', ...

  4. 动态链接库(DLL) 分类: c/c++ 2015-01-04 23:30 423人阅读 评论(0) 收藏

    动态链接库:我们经常把常用的代码制作成一个可执行模块供其他可执行文件调用,这样的模块称为链接库,分为动态链接库和静态链接库. 对于静态链接库,LIB包含具体实现代码且会被包含进EXE中,导致文件过大, ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. HDU4081 Qin Shi Huang's National Road System 2017-05-10 23:16 41人阅读 评论(0) 收藏

    Qin Shi Huang's National Road System                                                                 ...

随机推荐

  1. 【nodeJS】webstorm中设置nodej智能提示

  2. WebHttpBinding.ReaderQuotas 无法设置或者无法点出来

    项目需要引用System.Runtime.Serialization.dll 才能设置各项值: binding.ReaderQuotas.MaxDepth = ; binding.ReaderQuot ...

  3. 黄聪:360浏览器、chrome开发扩展插件教程(1)开发Chrome Extenstion其实很简单

    转载:http://www.cnblogs.com/walkingp/archive/2011/03/31/2001628.html Chrome的更新速度可以说前无古人,现在我每天开机的第一件事就是 ...

  4. 马士兵Spring-AOP-XML配置(2)

    一. UserDAO.java: package com.cy.dao; import com.cy.model.User; public interface UserDAO { public voi ...

  5. 1027代码审计平台 1-sonar scanner

    1.代码审计 1.1综合性的代码分析平台 sonar支持自定义规则,较多的公司使用 360火线 1.2IDE辅助功能 Xcode.Android studio 阿里巴巴Java开发手机ide插件支持 ...

  6. Web API 源码剖析之默认消息处理程序链--》路由分发器(HttpRoutingDispatcher)

    我们在上一节讲述了默认的DefaultServer(是一个类型为HttpServer的只读属性,详情请参考 Web API 源码剖析之全局配置).本节将讲述DefaultHandler(是一个Http ...

  7. lombok 的使用

    参考:https://blog.csdn.net/motui/article/details/79012846

  8. C++ 获取特定进程的CPU使用率<转>

    C++ 获取特定进程的CPU使用率 近来发现笔记本在关闭屏幕后风扇转得特别快,打开屏幕后看任务管理器,风扇马上减速,也没有发现大量占用CPU的进程.于是想写一个小程序在后台记录每个进程的CPU使用情况 ...

  9. 【转】关于BeanUtils.copyProperties的用法和优缺点

    一.简介:  BeanUtils提供对Java反射和自省API的包装.其主要目的是利用反射机制对JavaBean的属性进行处理.我们知道,一个JavaBean通常包含了大量的属性,很多情况下,对Jav ...

  10. kubernetes 示例 hello world

    本文所说的Hello world是一个web留言板应用,并且是基于PHP+Redis的两层分布式架构的web应用,前端PHP web网站通过访问后端Redis数据库完成用户留言的查询和添加功能,具备读 ...