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. uboot启动参数

    bootcmd=nand read.jffs2 0x30007FC0 kernel; bootm 0x30007FC0bootdelay=2baudrate=115200ethaddr=08:00:3 ...

  2. JVM学习笔记(二)------Java代码编译和执行的整个过程【转】

    转自:http://blog.csdn.net/cutesource/article/details/5904542 版权声明:本文为博主原创文章,未经博主允许不得转载. Java代码编译是由Java ...

  3. nexus启动不了

    nexus一分钟前还能正常启动,突然就启动不了,看了下启动文件,变成0KB就知道什么问题了,文件被系统洗了. 解决方案:重新解压缩文件包里复制一个过来.

  4. ectouch第四讲 之缓存文件的生成

    当第一次访问\mobile主页的时候,就会生成如下缓存文件:缓存文件存放在\mobile\data\cache\文件夹下 |-mobile |-data |-cache |-compiled [前台编 ...

  5. string转换成color转

    string转换成color             string col = "#FF8400";            this.BackColor = System.Draw ...

  6. Codeforces 746D:Green and Black Tea(乱搞)

    http://codeforces.com/contest/746/problem/D 题意:有n杯茶,a杯绿茶,b杯红茶,问怎么摆放才可以让不超过k杯茶连续摆放,如果不能就输出NO. 思路:首先,设 ...

  7. Linux学习之八——利用变量

    一.变量的使用 用$放在变量前面进行使用,例如: echo $PATH 为了和别的字符隔开,可以用{}和"",例如 echo ${PATH}nic echo "$PATH ...

  8. sql查询某条记录

    select * from (SELECT t.*,ROWNUM AS RN FROM AWARDISSUE_FOOTBALL t ORDER BY ID DESC) WHERE RN=2

  9. Unity-Animator深入系列---Foot IK

    回到 Animator深入系列总目录 最近在做一个demo,遇到了角色跑动不自然的问题(注意双腿): 后来得知勾选FootIK之后Unity会智能修复这类问题: 好像这个功能还能做到斜面地形匹配,不过 ...

  10. 覆盖率测试工具gcov的前端工具_LCOV

    http://my.oschina.net/alphajay/blog/33725 1.Gcov是进行代码运行的覆盖率统计的工具,它随着gcc的发布一起发布的,它的使用也很简单,需要在编译和链接的时候 ...