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. 【maven】maven项目移除Maven Dependencies后如何再添加进去

    比较着急这几天弄一个项目,所以匆忙间把maven项目的Maven Dependencies给remove掉了 如下图: 这下可好,整个项目报错了 解决方法: 对比了有Maven Dependencie ...

  2. fmri 实验设计 / 范式设计/ paradigm design

    reference:http://www.psychology.gatech.edu/cabi/Resources/Course/index.html sluggish 懒散的,无精打采的.哈哈,pp ...

  3. html之marquee会移动的文字

    该标签不是HTML3.2的一部分,并且只支持MSIE3以后内核,所以如果你使用非IE内核浏览器(如:Netscape)可能无法看到下面一些很有意思的效果 该标签是个容器标签 语法: <marqu ...

  4. 游戏用户接口设计的一些小原则(摘自 game coding complete)

    1.没有坏之前不要修理 2.简单的操作却有非常复杂的结果时,要小心设计. 3.记得给玩家反馈. 4.玩家不知道该功能,可能就根本不会用这个功能. 5.观察并持续改进.(给不熟悉该设计的人玩,站在他们后 ...

  5. MFC【17-3】线程和线程同步化

    17.3小知识点 17.3.1消息泵 编写一个应用程序,让它响应某菜单命令,画几千个椭圆. void CMFC线程View::OnStartDrawing(void) { m_bQuit=FALSE; ...

  6. springmvc实现简单的拦截器

    SpringMVC 中的Interceptor 拦截请求是通过HandlerInterceptor 来实现的.在SpringMVC 中定义一个Interceptor 非常简单,主要有两种方式,第一种方 ...

  7. 怎样在Ubuntu手机应用中得到全部的环境变量值

    我们在先前的例程中已经通过一些方法得到我们应用的一些环境变量值.这些值有的很实用.比方我们能够得到我们应用所仅仅能訪问的文件夹.在今天的例程中,我们来展示一种方法能够得到应用全部的环境变量.在我们的实 ...

  8. java web 拦截器、过滤器理解

    1.首先要明确什么是拦截器.什么是过滤器 1.1 什么是拦截器: 拦截器,在AOP(Aspect-Oriented Programming)中用于在某个方法或字段被访问之前,进行拦截然后在之前或之后加 ...

  9. 向项目中添加dtd文件实现代码提示

    我们在编辑代码的过程中,有代码提示的编辑工具总是受到青睐. 本文将讲解怎么在eclipse中加入dtd文件实现代码提示.myeclipse同理 选择window,选择perferences,然后拉到下 ...

  10. VS2013编译boost1.55库

    1. 官网下载最新的Boost库,我的是1.55 2. 在使用vs2013编译boost-1.55.0之前,先要给boost做下修改: boost_1_55_0\boost\intrusive\det ...