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是给定的.学生选修 ...
随机推荐
- ESLint – 可扩展的 JavaScript & JSX 校验工具
ESLint 是一个开源的 JavaScript 代码校验工具,最初是由 Nicholas C. Zakas 在2013年创建的.经常被用来发现问题的模式或代码,不符合特定的风格准则. ESLint ...
- js动态计算移动端rem
在做移动端web app的时候,众所周知,移动设备分辨率五花八门,虽然我们可以通过CSS3的media query来实现适配,例如下面这样: html { font-size : 20px; } @m ...
- No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active arch=x86_64, VALID_ARCHS=i386)
今天在运行一个老ios项目的时候,突然报错:No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active arch=x86_64, VAL ...
- 【读书笔记】iOS网络-同步请求,队列式异步请求,异步请求的区别
一,同步请求的最佳实践. 1,只在后台过程中使用同步请求,除非确定访问的是本地文件资源,否则请不要在主线程上使用. 2,只有在知道返回的数据不会超出应用的内存时才使用同步请求.记住,整个响应体都会位于 ...
- NSString方法与NSMutableString方法
NSString方法+(id) stringWithContentsOfFile:path encoding:enc error:err创建一个新字符串并将其设置为path指定的文件的内容,使用字符编 ...
- iOS--(UITableViewCell)、(UITableViewController)微信个人主页
本文主要实现了微信的个人主页的设置: 目录文件如下: 实现代码如下: RootTableViewController.h #import <UIKit/UIKit.h> @interfac ...
- cocoapods卸载与安装的各种坑
在mac上安装cocoapods,一路的坑啊,无数报错啊有木有! 本以为安装很简单,mac下都自带ruby,使用ruby的gem命令即可下载安装: $ sudo gem install cocoapo ...
- IOS学习资源收集--开发UI控件相关
收集的一些本人了解过的iOS开发UI控件相关的代码资源(本文持续补充更新) 内容大纲: 1.本人在github上也上传了我分装好的一些可重复利用的UI控件 2.计时相关的自定义UILabel控件 正文 ...
- nodejs events模块
var EventEmitter = require('events').EventEmitter; var emitter = new EventEmitter(); console.log(emi ...
- 每日Scrum(2)
今天是冲刺的第二天,小组主要做了界面的美化,加入了软件的开始动画,以及学校景点的美图介绍: 主要的问题在于除了开始界面,进入软件之后还是有待改进,功能的呈现有待加强.