hdu 3535 AreYouBusy 分组背包
AreYouBusy
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
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)?
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
#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 分组背包的更多相关文章
- HDU 3535 AreYouBusy(混合背包)
HDU3535 AreYouBusy(混合背包) http://acm.hdu.edu.cn/showproblem.php?pid=3535 题意: 给你n个工作集合,给你T的时间去做它们.给你m和 ...
- [HDU 3535] AreYouBusy (动态规划 混合背包 值得做很多遍)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3535 题意:有n个任务集合,需要在T个时间单位内完成.每个任务集合有属性,属性为0的代表至少要完成1个 ...
- HDU - 1712 (分组背包模板)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1712 题意:给你n个课程,每个课程有很多种学习方法,用的时间和取得的效果都不一样,现在你只有m天时间用来学 ...
- hdu 1712 (分组背包)
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=17676 这个问题让我对分组背包更清晰了一点,主要是这个问题: 使用一维数组的 ...
- HDU 3535 AreYouBusy (混合背包之分组背包)
题目链接 Problem Description Happy New Term! As having become a junior, xiaoA recognizes that there is n ...
- HDU 3535 AreYouBusy (混合背包)
题意:给你n组物品和自己有的价值s,每组有l个物品和有一种类型: 0:此组中最少选择一个 1:此组中最多选择一个 2:此组随便选 每种物品有两个值:是需要价值ci,可获得乐趣gi 问在满足条件的情况下 ...
- HDU 3535 AreYouBusy 经典混合背包
AreYouBusy Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Su ...
- hdu 3535 AreYouBusy
// 混合背包// xiaoA想尽量多花时间做ACM,但老板要求他在T时间内做完n堆工作,每个工作耗时ac[i][j],// 幸福感ag[i][j],每堆工作有m[i]个工作,每堆工作都有一个性质,/ ...
- HDU 1712 分组背包
ACboy needs your help Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
随机推荐
- java总结第四次//常用类
六.常用类 主要内容:Object类.String类.Date类.封装类 (一)Object类 1.Object类是所有Java类的根父类 2.如果在类的声明中未使用extends关键字指明其父类,则 ...
- java网络编程之UDP通讯
详细介绍了java中的网络通信机制,尤其是UDP协议,通过对UDP的基本使用进行举例说明如何使用UDP进行数据的发送接收,并举了两个小demo说明UDP的使用注意事项. UDP协议原理图解: UDP协 ...
- javax.xml.ws.soap.SOAPFaultException: 没有Header,拦截器实施拦截
客户端代码: client.getOutInterceptors().add(new AuthInterceptor("zhangsan", "123456") ...
- 更改MySQL数据文件目录位置
运维mysql,某些时候需要将数据文件更改到别的路径.以下介绍将mysql的数据文件从/var/lib/mysql迁移到/home/mysqldata/mysql下. 1.停止mysql $ serv ...
- Android系统版本与API Level对照表
Platform Version API Level VERSION_CODE Notes Android 4.2 17 JELLY_BEAN_MR1 Android 4.1, 4.1.1 16 ...
- iOS 序列化与反序列化
开篇 1到底这个序列化有啥作用? 面向对象的程序在运行的时候会创建一个复杂的对象图,经常要以二进制的方法序列化这个对象图,这个过程叫做Archiving. 二进制流可以通过网络或写入文件中(来源于某教 ...
- Python查看函数代码内容
方法1:使用help(random) >>> import random >>> help(random) Help on module random: NAME ...
- 每日一九度之题目1016:火星A+B
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5346 解决:1464 题目描述: 读入两个不超过25位的火星正整数A和B,计算A+B.需要注意的是:在火星上,整数不是单一进制的, ...
- MVC模式:实现数据库中数据的增删改查功能
*.数据库连接池c3p0,连接mysql数据库: *.Jquery使用,删除时跳出框,确定是否要删除: *.使用EL和JSTL,简化在jsp页面中插入的java语言 1.连接数据库 (1)导入连接数据 ...
- hdu4933 Miaomiao's Function
水水的计数题,关键在细节. import java.math.BigInteger; import java.util.Scanner; import java.io.*; public class ...