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. JavaScript强化教程——jQuery AJAX 实例

    什么是 AJAX?AJAX = 异步 JavaScript 和 XML(Asynchronous JavaScript and XML).简短地说,在不重载整个网页的情况下,AJAX 通过后台加载数据 ...

  2. Oracle11gR2用EXP导出时报EXP-00011错误的解决

    C:\>exp businessdata/businessdata file=dropcol.dmp tables=ACSTRULE,ARREARSCFG,ARREARS_REPORT_ACCT ...

  3. 微信小程序管理后台介绍

    微信小程序的管理后台,每次进入都需要扫码,还是特别不爽,现在微信小程序还没正式发布,很多人都还没看到管理后台,这里抢先发布出来 ------------------------------------ ...

  4. 小谈KVC中KeyPath的集合运算符

    由于知识点比较简单,这里不再陈述一大堆的原理,直入主题. KVC中的集合运算符有以下三类: 1.简单集合运算符:@avg.@sum.@max.@min.@count (只能用在集合对象中,对象属性必须 ...

  5. MVVM 模式下iOS项目目录结构详细说明

    ➠更多技术干货请戳:听云博客 我们在做项目的时候,会经常用到各种设计模式,最常见的要数 MVC (模型,视图,控制器)了.但是,今天我们要说的是另一种设计模式——MVVM. 所以 MVVM 到底是什么 ...

  6. 【代码笔记】iOS-手机验证码

    一,效果图. 二,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController : UIVi ...

  7. raw_input() 与 input() __ Python

    这两个均是 python 的内建函数,通过读取控制台的输入与用户实现交互.但他们的功能不尽相同.举两个小例子. 1 >>> raw_input_A = raw_input(" ...

  8. php array 分页

    $array=array("1","2","3","4","5","6",&qu ...

  9. go的环境变量设置

    GOROOT go的安装路劲 如:D:\Program Files\Go GOPATH go的工作路径 GOPATH可以设置多个.存放包文件.比如你引入 "xxx"包.那么go会去 ...

  10. js 静态私有变量

    特权方法:有权访问私有变量和私有函数的公有方法.在私有作用域中定义私有变量或函数,可以创建特权方法,如下: 示例1 (function(){ //私有变量和私有函数 var privateVariab ...