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. BOOST 实用手册(摘录自校友博客)

    1. 序言 现在学的东西很容易忘记,写这篇文章的目的是能让我在需要时快速找回当时的感觉.  Let's BOOST THE WORLD . 2. 编译:VC2005注意 在 属性->C/C++- ...

  2. 关于weblogic server对docker的支持

    Docker是目前比较热门的一个技术话题,WebLogic Server从12.1.3版本支持Docker,但对于操作系统和内核有一定的要求,具体参考下表 我曾在ubuntu,Oracle Enter ...

  3. pycharm的插件pylint报错:java.lang.Throwable: Write-unsafe context! Model changes are allowed from write-safe contexts only. Please ensure you're using invokeLater/invokeAndWait with a correct modality stat

    java.lang.Throwable: Write-unsafe context! Model changes are allowed from write-safe contexts only. ...

  4. static_cast ,reinterpret_cast

    用法:static_cast < type-id > ( expression ) 该运算符把expression转换为type-id类型,但没有运行时类型检查来保证转换的安全性.它主要有 ...

  5. vim文本编辑工具—修改文件内容

    在vim中进行文本替换: 1.替换当前行中的from: :s/from/to/    (其中s是英文单词substitute第一个字母,表示替换的意思) :s/from/to/  ==  :.s/fr ...

  6. xss的高级利用

    以往对XSS的利用大多数都是针对于挂马,钓鱼,盗cookie等,这些方式并没有真正发挥到XSS的作用,因为很少人能了解XSS的实质,会话劫持,浏览器劫持,XSS能做到的东西远远超乎我们的想象. 一 X ...

  7. Hibernate简介与实例

    一.Hibernate简介 1.什么是Hibernate? Hibernate是数据持久层的一个轻量级框架.数据持久层的框架有很多比如:iBATIS,myBatis,Nhibernate,Siena等 ...

  8. 《大规模web服务开发技术》笔记

    前段时间趁空把<大规模web服务开发技术>这本书看完了,今天用一下午时间重新翻了一遍,把其中的要点记了下来,权当复习和备忘.由于自己对数据压缩.全文检索等还算比较熟,所以笔记内容主要涉及前 ...

  9. 寻找i*j=m的个数

    问题描述 3*3的矩阵内容. 1 2 3 2 4 6 3 6 9 即a[i][j](1<=i<=n,1<=j<=n)=i*j. 问一个这样n*n的矩阵里面,里面m出现的次数. ...

  10. axios 同时执行多个请求

    http://chuansong.me/n/394228451820 同时执行多个请求 axios.all([ axios.get('https://api.github.com/xxx/1'), a ...