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是给定的.学生选修 ...
随机推荐
- Egret白鹭H5小游戏开发入门(三)
前言: 在上一篇文章中着重介绍了H5小游戏开发的起步阶段,如Wing面板的使用,素材的处理,类的说明等等,那么今天主要是涉及到场景的创建,loading的修改等等的代码编写. 对于这一节,我在讲解的过 ...
- C# 获得MP4时长
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...
- Ioc Autofac心得
对于这个容器注入,个人也不是很熟悉,很多还不懂,只会基本的操作,几天把它记录下来,说不定以后帮助就大了呢,这方面跟安卓差距还是挺大的 下面记录下应用的流程 步骤: 1.添加应用 2.重写工厂(这里讲的 ...
- C语言中的数组的一些笔记
C语言是面向过程的语言. 计算数组长度: Int count =sizeof(ages)/sizeof(int); C语言里面输出字符串,必须以'\0'结束,如果没有则一直执行下去. Char nam ...
- 电脑公司最新GHOST WIN7系统32,64位优化精简版下载
系统来自系统妈:http://www.xitongma.com 电脑公司最新GHOST win7系统32位优化精简版V2016年3月 系统概述 电脑公司ghost win7 x86(32位)万能装机版 ...
- OC NSString(字符串)
OC NSString(字符串) 多行文字字面量 NSString * string = @"abC" @"DEF" @"hjk" @&qu ...
- 学习Coding-iOS开源项目日志(四)
Hello,大家好,好久没写博客了,今天再次来研究研究Coding源码,久违了. 前 言:作为初级程序员,想要提高自己的水平,其中一个有效的学习方法就是学习别人好的项目.本篇开始会陆续更新本人对git ...
- mysql命令(数据库备份与恢复)
本地: 1.进入MySQL目录下的bin文件夹:e:回车: e:\>cd mysql\bin? 回车 2.导出数据库:mysqldump -u 用户名 -p 数据库名 > 导出的文件名 范 ...
- .Net中使用aliases让相同命名空间的dll引用共存
有些不得已的时候,我们需要同时在代码中使用某个dll的不同版本.比如用低版本的dll中的方法导出数据,然后使用高版本的方法导入数据来实现数据的升级. 又或者需要同时使用第三方的dll不同版本.如何使它 ...
- MySQL数据库备份命令
原文参考:MySQL数据库备份的命令 - 司南 mysqldump -hhostname -uusername -ppassword databasename > backupfile.sql备 ...