http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3703

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

思路:0-1背包

<span style="font-size:18px;">#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=1010;
int value[maxn],a[maxn],fv[maxn];
int vis[55][maxn];
int order[55];
int main()
{
int N,length,n;
cin>>N;
while(N--)
{
int time=0,sumtime=0,numbers=0;
memset(vis,0,sizeof(vis));
memset(fv,0,sizeof(fv));
cin>>length>>n;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=n;i++)cin>>value[i];
for(int i=1;i<=n;i++)
{
for(int j=length;j>=a[i];j--)
{
if(fv[j]<fv[j-a[i]]+value[i])
{
fv[j]=fv[j-a[i]]+value[i];
vis[i][j]=1;
}
}
}
int cnt=0;
int i=n;
int j=length;
for(;i>0;i--)
{
if(vis[i][j]==1)
{
order[cnt++]=a[i];
j -= a[i];
}
}
sort(order,order+cnt);
for(int i=0;i<cnt;i++)
{
time +=order[i];
sumtime +=time;
}
cout<<fv[length]<< " " << cnt << " " << sumtime << endl;
}
return 0;
}</span>

ZOJ 3703 Happy Programming Contest(0-1背包)的更多相关文章

  1. ZOJ 3703 Happy Programming Contest

    偏方记录背包里的物品.....每个背包的价值+0.01 Happy Programming Contest Time Limit: 2 Seconds      Memory Limit: 65536 ...

  2. ZOJ 3703 Happy Programming Contest(DP)

    题目链接 输出路径,搞了一个DFS出来,主要是这里,浪费了好长时间. #include <cstdio> #include <string> #include <cstr ...

  3. Gym 101102A Coins -- 2016 ACM Amman Collegiate Programming Contest(01背包变形)

    A - Coins Time Limit:3000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Descript ...

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

  5. zoj The 12th Zhejiang Provincial Collegiate Programming Contest Capture the Flag

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5503 The 12th Zhejiang Provincial ...

  6. zoj The 12th Zhejiang Provincial Collegiate Programming Contest Team Formation

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5494 The 12th Zhejiang Provincial ...

  7. zoj The 12th Zhejiang Provincial Collegiate Programming Contest Beauty of Array

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5496 The 12th Zhejiang Provincial ...

  8. zoj The 12th Zhejiang Provincial Collegiate Programming Contest Lunch Time

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5499 The 12th Zhejiang Provincial ...

  9. zoj The 12th Zhejiang Provincial Collegiate Programming Contest Convert QWERTY to Dvorak

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5502  The 12th Zhejiang Provincial ...

随机推荐

  1. 【Rocket MQ】RocketMQ4.2.0 和 spring boot的结合使用,实现分布式事务

    RocketMQ4.2.0 和 spring boot的结合使用,实现分布式事务 参考地址:https://www.jianshu.com/p/f57de40621a0

  2. Python 学习建议(个人愚见)

    前言 本科毕业已经5年+,一直在做iOS开发. 工作方面:从刚入门的小菜鸟码农,后面到BAT里混过两年,到现在带10个人的Team Leader,收入尚可. 生活状态:已婚,儿子刚满1岁,有一定存款, ...

  3. es6数组去重复

    var arr=[1,1,2,3,5,7,7,7] arr=Array.from(new Set(arr))

  4. 阿里云NAS使用方法

    1.创建文件系统 #在创建文件系统页面,填写各项参数.根据项目需求选择存储类型 2.添加挂载点 文件系统实例创建完成后,您需要为文件系统添加挂载点,用于计算节点(ECS 实例.E-HPC 或容器服务) ...

  5. 用java源代码学数据结构<七>: BST

    /* * 以int类为例 * 其它的类必须能够比较 * */ //二叉搜索树的节点点 class BSTNode{ int item; BSTNode lc; BSTNode rc; BSTNode ...

  6. BS中保存参数

    开发中经常需要将值存起来,当点击某一项时以便知道点击了哪一项. 一:应用JS页面跳转(牛腩中讲到) HTML: <td class="txt c"><a href ...

  7. sudo 添加

    sudo 添加 /etc/sudoers 找到root  ALL=(ALL)  ALL那一行, 复制之后,修改用户名:

  8. Win7双屏显示设置

    双显示器:一个是T410自己的屏幕,一个是宏基的Acer1296*768显示器. 连接:将宏基显示器的Display端子连接到笔记本的Display口上,电源接上. 设置过程: 1.右键点屏幕,选“S ...

  9. Python cx_Oracle问题处理

    今天第一次使用Python连接Oracle数据库(多么可怕,三年码农没用Python手动连过Oracle) 首先: pip install cx_Oracle 好,安装完成,测试代码如下: from ...

  10. JavaScript的String对象

    1.创建String对象 Html标签的格式编排方法:可以将String对象的字符串内容输出成对应的html标签. 示例: var str = "JavaScript程序设计"; ...