ZOJ 3703 Happy Programming Contest(0-1背包)
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背包)的更多相关文章
- ZOJ 3703 Happy Programming Contest
偏方记录背包里的物品.....每个背包的价值+0.01 Happy Programming Contest Time Limit: 2 Seconds Memory Limit: 65536 ...
- ZOJ 3703 Happy Programming Contest(DP)
题目链接 输出路径,搞了一个DFS出来,主要是这里,浪费了好长时间. #include <cstdio> #include <string> #include <cstr ...
- Gym 101102A Coins -- 2016 ACM Amman Collegiate Programming Contest(01背包变形)
A - Coins Time Limit:3000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Descript ...
- 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 ...
- 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 ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Team Formation
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5494 The 12th Zhejiang Provincial ...
- 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 ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Lunch Time
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5499 The 12th Zhejiang Provincial ...
- 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 ...
随机推荐
- java中关于volatile的理解疑问?
作者:xyzZ链接:https://www.zhihu.com/question/49656589/answer/117826278来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请 ...
- 未能加载文件或程序集 Version Culture=neutral, PublicKeyToken=
最近项目报错 未能加载文件或程序集"Microsoft.Practices.EnterpriseLibrary.Data, Version=4.1.0.0, Culture=neutral, ...
- unity3d的矩阵元素存储方式
想知道u3d矩阵各个元素的存储方式,所以测试了一下 Matrix4x4 m = Matrix4x4.TRS(new Vector3(1, 2, 3), Quaternion.Euler(0, 0, 3 ...
- TensorFlow------读取图片实例
TensorFlow------读取图片实例: import tensorflow as tf import os def readpic(filelist): ''' 读取人物图片并转换成张量 :p ...
- Vue使用中遇到问题汇总(一)32个
1.安装一些需要编译的包:提示没有安装python.build失败等 因为一些 npm 的包安装需要编译的环境,mac 和 linux 都还好,大多都齐全 .window 用户依赖 visual st ...
- maven install时报错Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test
事故现场: 解决办法: 一是命令行, mvn clean package -Dmaven.test.skip=true 二是写入pom文件, <plugin> <groupId> ...
- electron的安装
1.安装 node.js https://nodejs.org/en/ 2.安装asar npm install -g asar 3.安装atom https://atom.io/ 4.安装elect ...
- js知识梳理2:对象属性的操作
1.属性的查询和设置 ①基本语法 这个简单,可以通过点(.)或方括号([])运算来获取属性的值,注意点运算符后的标识符不能是保留字,方括号内的表达式必须返回字符串或返回一个可以转换成字符串的值. va ...
- taro + taro-ui + dva
taro的安装及使用 安装 Taro 开发工具 @tarojs/cli 使用 npm 或者 yarn 全局安装,或者直接使用npx $ npm install -g @tarojs/cli $ yar ...
- git push --set-upstream origin
设置本地分支追踪远程分支 之后就可以直接使用git push提交代码