AreYouBusy

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

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个分组,s=0最少取一个,s=1最多取一个,s=2,01背包;
思路:分组背包;
   s=0,hdu 3033;
   s=1,hdu 1712;
   s=2,01背包;
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
const int N=1e3+,M=4e6+,inf=1e9+,mod=1e9+;
const ll INF=1e18+;
int dp[N][N];
int v[N],w[N];
// 0 分组最多一个
// 1 分组最少一个
// 2 01背包
int main()
{
int n,T;
while(~scanf("%d%d",&n,&T))
{
memset(dp[],,sizeof(dp[]));
for(int i=;i<=n;i++)
{
int x,flag;
scanf("%d%d",&x,&flag);
for(int i=;i<=x;i++)
scanf("%d%d",&v[i],&w[i]);
if(flag==)
{
for(int t=;t<=T;t++)
dp[i][t]=-inf;
for(int t=;t<=x;t++)
{
for(int j=T;j>=v[t];j--)
{
dp[i][j]=max(dp[i][j],dp[i][j-v[t]]+w[t]);
dp[i][j]=max(dp[i][j],dp[i-][j-v[t]]+w[t]);
}
}
}
else if(flag==)
{
for(int t=;t<=T;t++)
dp[i][t]=dp[i-][t];
for(int t=;t<=x;t++)
{
for(int j=T;j>=v[t];j--)
{
dp[i][j]=max(dp[i][j],dp[i-][j-v[t]]+w[t]);
}
}
}
else
{
for(int t=;t<=T;t++)
dp[i][t]=dp[i-][t];
for(int t=;t<=x;t++)
{
for(int j=T;j>=v[t];j--)
{
dp[i][j]=max(dp[i][j],dp[i][j-v[t]]+w[t]);
dp[i][j]=max(dp[i][j],dp[i-][j-v[t]]+w[t]);
}
}
}
}
if(dp[n][T]>=)
printf("%d\n",dp[n][T]);
else
printf("-1\n");
}
return ;
}

hdu 3535 AreYouBusy 分组背包的更多相关文章

  1. HDU 3535 AreYouBusy(混合背包)

    HDU3535 AreYouBusy(混合背包) http://acm.hdu.edu.cn/showproblem.php?pid=3535 题意: 给你n个工作集合,给你T的时间去做它们.给你m和 ...

  2. [HDU 3535] AreYouBusy (动态规划 混合背包 值得做很多遍)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3535 题意:有n个任务集合,需要在T个时间单位内完成.每个任务集合有属性,属性为0的代表至少要完成1个 ...

  3. HDU - 1712 (分组背包模板)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1712 题意:给你n个课程,每个课程有很多种学习方法,用的时间和取得的效果都不一样,现在你只有m天时间用来学 ...

  4. hdu 1712 (分组背包)

    http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=17676 这个问题让我对分组背包更清晰了一点,主要是这个问题: 使用一维数组的 ...

  5. HDU 3535 AreYouBusy (混合背包之分组背包)

    题目链接 Problem Description Happy New Term! As having become a junior, xiaoA recognizes that there is n ...

  6. HDU 3535 AreYouBusy (混合背包)

    题意:给你n组物品和自己有的价值s,每组有l个物品和有一种类型: 0:此组中最少选择一个 1:此组中最多选择一个 2:此组随便选 每种物品有两个值:是需要价值ci,可获得乐趣gi 问在满足条件的情况下 ...

  7. HDU 3535 AreYouBusy 经典混合背包

    AreYouBusy Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Su ...

  8. hdu 3535 AreYouBusy

    // 混合背包// xiaoA想尽量多花时间做ACM,但老板要求他在T时间内做完n堆工作,每个工作耗时ac[i][j],// 幸福感ag[i][j],每堆工作有m[i]个工作,每堆工作都有一个性质,/ ...

  9. HDU 1712 分组背包

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

随机推荐

  1. 【python cookbook】【字符串与文本】8.编写多行模式的正则表达式

    问题:用正则表达式对一段文本块做匹配,但是希望在进行匹配时能够跨越多行 解决方案: 1.正则表达式添加对换行符的支持: 2.re.compile()函数一个有用的标记-re.DOTALL使得正则表达式 ...

  2. scala多个构造函数的定义方法

    直接上代码: package com.test.scalaw.test.demo /** * scala定义多个构造函数, * 另外,Scala中有只有一个主要构造函数,其他都是辅助构造函数.而且需要 ...

  3. MySQL与SQL比较有那些区别呢

    MySQL是一个逐渐完善的过程,使用前期版本时会遇到一些问题,通常搞得莫名其妙,在版本选择上尽量选择最新的. 1.在5.03以前版本中,存储varchar型数据时,后面的空格会被忽视掉,前面的空格会保 ...

  4. ci中简单实用的权限管理

    实用的权限管理 对多数网站来说,使用完整的rbac权限管理杀鸡用牛刀绝对的吃力不讨好,因为我们只是简单分角色然后对角色进行管理行使其相对于的角色赋予的权限; 在实际的开发中用位运算来对权限进行验证是十 ...

  5. A Knight's Journey 分类: POJ 搜索 2015-08-08 07:32 2人阅读 评论(0) 收藏

    A Knight's Journey Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 35564 Accepted: 12119 ...

  6. Tiling 分类: POJ 2015-06-17 15:15 8人阅读 评论(0) 收藏

    Tiling Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8091   Accepted: 3918 Descriptio ...

  7. UVa 489,紫书P79,刽子手游戏

    题目链接:https://uva.onlinejudge.org/external/4/489.pdf 这个题很像之前的一个拓扑排序的题目,思路类似咯. 程序模块化: 每次判断一个字母,lose,wi ...

  8. 通过PowerShell查看Android端log信息

    在Windows下我们可以通过在cmd中输入adb logcat相关命令来查看安卓设备上的log信息,这在PowerShell里也可以做到.所以方便做成一个脚本,以便复用.代码如下: function ...

  9. CentOS 安装SolrCloud

    1.什么是SolrCloud SolrCloud(solr 云)是Solr提供的分布式搜索方案,当你需要大规模,容错,分布式索引和检索能力时使用 SolrCloud.当一个系统的索引数据量少的时候是不 ...

  10. linux--基础学习笔记--软件安装