HDU3535AreYouBusy[混合背包 分组背包]
AreYouBusy
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3985 Accepted Submission(s):
1580
As having become a junior, xiaoA
recognizes that there is not much time for her to AC problems, because there are
some other things for her to do, which makes her nearly mad.
What's more, her
boss tells her that for some sets of duties, she must choose at least one job to
do, but for some sets of things, she can only choose at most one to do, which is
meaningless to the boss. And for others, she can do of her will. We just define
the things that she can choose as "jobs". A job takes time , and gives xiaoA
some points of happiness (which means that she is always willing to do the
jobs).So can you choose the best sets of them to give her the maximum points of
happiness and also to be a good junior(which means that she should follow the
boss's advice)?
with two integers n and T (0<=n,T<=100) , n sets of jobs for you to choose
and T minutes for her to do them. Follows are n sets of description, each of
which starts with two integers m and s (0<m<=100), there are m jobs in
this set , and the set type is s, (0 stands for the sets that should choose at
least 1 job to do, 1 for the sets that should choose at most 1 , and 2 for the
one you can choose freely).then m pairs of integers ci,gi follows
(0<=ci,gi<=100), means the ith job cost ci minutes to finish and gi points
of happiness can be gained by finishing it. One job can be done only once.
of happiness we can choose from all jobs .if she can’t finish what her boss
want, just output -1 .
2 1
2 5
3 8
2 0
1 0
2 1
3 2
4 3
2 1
1 1
3 4
2 1
2 5
3 8
2 0
1 1
2 8
3 2
4 4
2 1
1 1
1 1
1 0
2 1
5 3
2 0
1 0
2 1
2 0
2 2
1 1
2 0
3 2
2 1
2 1
1 5
2 8
3 2
3 8
4 9
5 10
13
-1
-1
题意:n组,每组m个物品,有三种类型:至少选一个,至多选一个,随便选
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=,INF=1e9;
int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-; c=getchar();}
while(c>=''&&c<=''){x=x*+c-''; c=getchar();}
return x*f;
}
int n,t,m,s,v[N],w[N];
int d[N][N];
int main(){
while(cin>>n>>t){
memset(d,,sizeof(d));
for(int i=;i<=n;i++){
m=read();s=read();
for(int x=;x<=m;x++){
v[x]=read();w[x]=read();
}
if(s==){
for(int j=;j<=t;j++) d[i][j]=-INF;
for(int x=;x<=m;x++)
for(int j=t;j>=v[x];j--)
d[i][j]=max(d[i][j],max(d[i][j-v[x]]+w[x],d[i-][j-v[x]]+w[x]));
}
else if(s==){
for(int j=;j<=t;j++) d[i][j]=d[i-][j];
for(int x=;x<=m;x++)
for(int j=t;j>=v[x];j--)
d[i][j]=max(d[i][j],d[i-][j-v[x]]+w[x]);
}
else if(s==){
for(int j=;j<=t;j++) d[i][j]=d[i-][j];
for(int x=;x<=m;x++)
for(int j=t;j>=v[x];j--)
d[i][j]=max(d[i][j],d[i][j-v[x]]+w[x]);
}
}
printf("%d\n",max(d[n][t],-));
}
}
HDU3535AreYouBusy[混合背包 分组背包]的更多相关文章
- HDU 1561 The more, The Better【树形DP/有依赖的分组背包】
ACboy很喜欢玩一种战略游戏,在一个地图上,有N座城堡,每座城堡都有一定的宝物,在每次游戏中ACboy允许攻克M个城堡并获得里面的宝物.但由于地理位置原因,有些城堡不能直接攻克,要攻克这些城堡必须先 ...
- HDU3535AreYouBusy(分组背包)
http://acm.hdu.edu.cn/showproblem.php?pid=3535 分组背包,每一组加了以下三个限制 0 stands for the sets that should ch ...
- HDU 1712 ACboy needs your help(分组背包)
题意:给你n的课程组,每个课程组有m个课程,每个课程有一个完成时间与价值.问在m天内每组课程组最多选择一个,这样可以得到的最大价值是多少 题解:分组背包,其实就是每个课程组进行01背包,再在课程组内部 ...
- Codeforces Round #383 (Div. 2) D 分组背包
给出一群女孩的重量和颜值 和她们的朋友关系 现在有一个舞台 ab是朋友 bc是朋友 ac就是朋友 给出最大承重 可以邀请这些女孩来玩 对于每一个朋友团体 全邀请or邀请一个or不邀请 问能邀请的女孩的 ...
- HDU 3033 分组背包变形(每种至少一个)
I love sneakers! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 1712 分组背包
ACboy needs your help Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- Codeforces Round #383 (Div. 2) D. Arpa's weak amphitheater and Mehrdad's valuable Hoses(分组背包+dsu)
D. Arpa's weak amphitheater and Mehrdad's valuable Hoses Problem Description: Mehrdad wants to invit ...
- POJ1837 Balance[分组背包]
Balance Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 13717 Accepted: 8616 Descript ...
- Codevs1378选课[树形DP|两种做法(多叉转二叉|树形DP+分组背包)---(▼皿▼#)----^___^]
题目描述 Description 学校实行学分制.每门的必修课都有固定的学分,同时还必须获得相应的选修课程学分.学校开设了N(N<300)门的选修课程,每个学生可选课程的数量M是给定的.学生选修 ...
随机推荐
- 高性能javascript学习笔记系列(2)-数据存取
参考 高性能javascript Tom大叔深入理解javascript系列 相关概念 1.执行上下文 当控制器转到ecmascript可执行代码的时候,就会进入一个执行上下文,执行上下文是以堆栈 ...
- Box2D自定义重力
需要给刚体添加一个自定义的属性:m_customGravity,这样就可以动态的修改每一个刚体自定义的重力,查找box2d源码大约在5486行,加上红色的一句代码 b2Island.prototype ...
- sql server 2014预览版发布
MSDN发布sql server2014预览版,如下图: SQL Server 2014新特性: 微软SQL Server部门主管Eron Kelly介绍,通过将交易处理放到内存中进行,新的SQL S ...
- 客户端调用服务端webservice的端口问题
今天有一个同事过来问:他有一个程序在A服务器上调第三方B服务器短信发送服务接口(webservice),无论是否发送成功,服务接口都会返回状态.现在客户要做每一个服务器 做入站端口管控,一切不必要的端 ...
- sqlmap笔记
sqlmap -u "注入链接" --其他参数或命令 (-v 1表示回显出注入过程) [判断指定字段是否存在注入点]当链接包含两个参数时,可用-p开关选择要注入的参数,例检测id是 ...
- 之四:CATransition - 转场动画
关键属性: type 过渡效果 kCATransitionFade 淡出 kCATransitionMoveIn 覆盖原图 kCATransitionPush 推出 kCATransition ...
- dispatch
GCD提供了并管理着若干FIFO队列(queues),可以通过block的形式向这些FIFO序列提交任务.GCD同时维护着一个线程池,所有的任务在线程池的线程运行. 系统提供的队列 main queu ...
- Android studio修改Logcat颜色
Android studio默认的Logcat配色不利于阅读,我们可以修改自定义自己的颜色配置
- Swift-Switch穿透
switch vegetable { case "celery": print("Add some raisins and make ...
- 转:能和LoadRunner匹敌的VS2010/2012Web负载测试
原文出处:http://www.cnblogs.com/aarond/archive/2013/04/18/performance.html VS自带的Web负载测试真的很大程度上能和专业的loadr ...