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. Positional parameter are considered deprecated; use named parameters or JPA-style positional parameters instead.

    这行代码: List<Cat> catList =session.createQuery("from Cat p where p.name.first_name=?") ...

  2. oracle nvl和nvl2的区别

    一直用oracle nvl函数,最近发现还有一个nvl2函数: nvl(a,b) 如果a不为null 则返回a,如果a为null则返回b; nvl2(a,b,c) ,如果a不为null 则返回b,如果 ...

  3. 杭电1009-FatMouse' Trade

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  4. [团队项目]SCRUM项目6.0 7.0 (新)

    6.0----------------------------------------------------- sprint演示 1.坚持所有的sprint都结束于演示. 团队的成果得到认可,会感觉 ...

  5. c# Beginlnvoke 委托

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  6. C/C++ 调用qsort/sort 对字符数组排序的cmp函数写法

    这个问题屡次碰到解决之后再次遇到又忘记怎么弄了,这次打算彻底搞清楚. ·C 首先对所谓字符数组的排序应该是对(char)*a[]数组而非(char)a[][]进行的排序,后者是无法直接调用qsort实 ...

  7. 安装python-devel 在升级到python2.7之后

    分别执行如下命令: # yum update # yum install centos-release-SCL # yum search all python27 在搜索出的列表中发现python27 ...

  8. C#中汉诺塔问题的递归解法

    百度测试部2015年10月份的面试题之——汉诺塔. 汉诺塔就是将一摞盘子从一个塔转移到另一个塔的游戏,中间有一个用来过度盘子的辅助塔. 百度百科在此. 游戏试玩在此. 用递归的思想解决汉诺塔问题就是分 ...

  9. LoadRunner使用之变量关联

    性能测试LR小结之参数关联(LoadRunner11.0) 关联对于LR是经常需要用到的,本章使用简单登录来介绍关联功能. 1.       Q:何为关联? 所谓的关联就是把脚本中某些写死的代码(ha ...

  10. 2016 ACM/ICPC Asia Regional Qingdao Online HDU5883

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=5883 解法:先判断是不是欧拉路,然后枚举 #pragma comment(linker, "/S ...