AreYouBusy

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3985    Accepted Submission(s):
1580

Problem Description
Happy New Term!
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)?
 
Input
There are several test cases, each test case begins
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.
 
Output
One line for each test case contains the maximum points
of happiness we can choose from all jobs .if she can’t finish what her boss
want, just output -1 .
 
Sample Input
3 3
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

 
Sample Output
5
13
-1
-1
 
Author
hphp
 
Source

题意:n组,每组m个物品,有三种类型:至少选一个,至多选一个,随便选
 

d[i][j]表示前i组体积j的最大值
至少选一个:d[i][j]=-INF,保证了至少一个
      d[i][j]=max(d[i][j],max(d[i][j-v[x]]+w[x],d[i-1][j-v[x]]+w[x])) 因为可以选多个 【WARN:不能分成两次max,因为保证至少选一个-INF】
至多选一个:d[i][j]=d[i-1][j],d[i][j]=max(d[i][j],d[i-1][j-v[x]]+w[x]) 可以不选,普通分组背包
随便:d[i][j]=d[i-1][j],d[i][j]=max(d[i][j],d[i][j-v[x]]+w[x]); 可以不选,也可以选多个
#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[混合背包 分组背包]的更多相关文章

  1. HDU 1561 The more, The Better【树形DP/有依赖的分组背包】

    ACboy很喜欢玩一种战略游戏,在一个地图上,有N座城堡,每座城堡都有一定的宝物,在每次游戏中ACboy允许攻克M个城堡并获得里面的宝物.但由于地理位置原因,有些城堡不能直接攻克,要攻克这些城堡必须先 ...

  2. HDU3535AreYouBusy(分组背包)

    http://acm.hdu.edu.cn/showproblem.php?pid=3535 分组背包,每一组加了以下三个限制 0 stands for the sets that should ch ...

  3. HDU 1712 ACboy needs your help(分组背包)

    题意:给你n的课程组,每个课程组有m个课程,每个课程有一个完成时间与价值.问在m天内每组课程组最多选择一个,这样可以得到的最大价值是多少 题解:分组背包,其实就是每个课程组进行01背包,再在课程组内部 ...

  4. Codeforces Round #383 (Div. 2) D 分组背包

    给出一群女孩的重量和颜值 和她们的朋友关系 现在有一个舞台 ab是朋友 bc是朋友 ac就是朋友 给出最大承重 可以邀请这些女孩来玩 对于每一个朋友团体 全邀请or邀请一个or不邀请 问能邀请的女孩的 ...

  5. HDU 3033 分组背包变形(每种至少一个)

    I love sneakers! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  6. HDU 1712 分组背包

    ACboy needs your help Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  7. 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 ...

  8. POJ1837 Balance[分组背包]

    Balance Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 13717   Accepted: 8616 Descript ...

  9. Codevs1378选课[树形DP|两种做法(多叉转二叉|树形DP+分组背包)---(▼皿▼#)----^___^]

    题目描述 Description 学校实行学分制.每门的必修课都有固定的学分,同时还必须获得相应的选修课程学分.学校开设了N(N<300)门的选修课程,每个学生可选课程的数量M是给定的.学生选修 ...

随机推荐

  1. jQuery静态方法type使用和源码分析

    jQuery.type方法是检测数据类型的工具方法,在分析其用法之前先总结下js给我们提供了那些监测数据类型的方法: 一.typeof 操作符 下面是测试代码 var data=[],a='123', ...

  2. FlippingBook使用教程

    FlippingBook是一款收费的图书翻页效果的flash播放器.在线预览地址:FlippingBook,破解版下载地址 备用下载地址 预览效果: 它的文件结构如下: 其中:css文件夹是一个简单的 ...

  3. SharePoint解决The security validation for this page is invalid.

    我是在一个service后台用object model去check in一个spfile的时候报的这个错.这是SharePoint的一种保护机制,在处理不能确定是安全的请求时,sharepoint就会 ...

  4. java field, property,variable及getField和getDeclaredField的区别

    java 里面的field ,property, attribute,variable的区别 field: 就是定义的用于保存数据的字段 property: property是用于描述类中的特征,所以 ...

  5. iOS中响应者链条-触摸事件

    总体来说,分2个步骤: 一,从上到下寻找合适的控件来处理这个触摸事件.如下图,如果点击了黄色4,则UIApplication -> UIWindow -> 1白色 -> 2橙色 -& ...

  6. iOS如何获取网络图片(三)有沙盒的

    沙盒 沙盒简介 默认情况下,每个沙盒含有3个文件夹:Documents, Library 和 tmp.因为应用的沙盒机制,应用只能在几个目录下读写文件 Documents:苹果建议将程序中建立的或在程 ...

  7. 小结RunLoop

    Core Foundation中关于RunLoop的5个类 CFRunLoopRef CFRunLoopModeRef CFRunLoopSourceRef CFRunLoopTimerRef CFR ...

  8. iOS-点击推送消息跳转处理

    当用户通过点击通知消息进入应用时 - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDi ...

  9. IOS开发之代理的设计小技巧

    1.关于代理对象的设计小技巧 在设计一个类,需要通过代理和协议来从外部获取需要的动态的数据.那么在这里设计使用代理会有两种方法. <第一种方法> 也是比较常见的: 在你设计的类中,声明一个 ...

  10. django 验证用户是否登陆

    第一步 指定一下登陆url. url(r'^accounts/login/$', include(xadmin.site.urls)), 由于我用的xadmin故而指向了xadmin,如果使用默认的a ...