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 ...
随机推荐
- socket心跳包机制实践与理解
实现Socket心跳包主要分为两大类,第一采用tcp自带的KeepAlive,第二是自定义心跳包,恰巧我在产品VICA中都使用过,下面就这两种心跳包机制谈谈个人的理解与感受. 首先第一种KeepAli ...
- CKFinder的_thumbs缓存文件夹
<CKFinder2.0.2的使用与破解> 作者: 宓晨 说下背景,发下牢骚! 由于网站需要支持对图片的上传以及操作的管理,还有文字+图片的组合上传.问了一下同 ...
- Codeforces Round #313 (Div. 1) Gerald's Hexagon
http://codeforces.com/contest/559/problem/A 题目大意:按顺序给出一个各内角均为120°的六边形的六条边长,求该六边形能分解成多少个边长为1的单位三角形. 解 ...
- IP编址
IP地址 /include/linux/inetdevice.h,定义IPV4专用的网络设备相关的结构.宏等 /net/ipv4/devinet.c.支持IPV4特性的设备操作接口 数据组织 net_ ...
- Android 开发之 ---- bootloader (LK)
LK是什么 LK 是 Little Kernel 它是 appsbl (Applications ARM Boot Loader)流程代码 ,little kernel 是小内核小操作系统. LK ...
- Linux驱动mmap内存映射
mmap在linux哪里? 什么是mmap? 上图说了,mmap是操作这些设备的一种方法,所谓操作设备,比如IO端口(点亮一个LED).LCD控制器.磁盘控制器,实际上就是往设备的物理地址读写数据. ...
- TensorFlow进阶(一)----张量的阶和数据类型
张量的阶和数据类型 TensorFlow用张量这种数据结构来表示所有的数据.你可以把一个张量想象成一个n维的数组或列表.一个张量有一个静态类型和动态类型的维数.张量可以在图中的节点之间流通.其实张量更 ...
- Perforce查看workspace sync到的changlist
一 查看workspace sync到的changelist perforce的workspace其实是一些特定版本的文件的 结合,相比只将workspace对应到某个特定的changelist,此方 ...
- Bayesian statistics
文件夹 1Bayesian model selection贝叶斯模型选择 1奥卡姆剃刀Occams razor原理 2Computing the marginal likelihood evidenc ...
- (转)dubbo design
框架设计 整体设计 图例说明: 图中左边淡蓝背景的为服务消费方使用的接口,右边淡绿色背景的为服务提供方使用的接口, 位于中轴线上的为双方都用到的接口. 图中从下至上分为十层,各层均为单向依赖,右边的黑 ...