AreYouBusy

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5176    Accepted Submission(s): 2069

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

题意 :三类型工作,至多做一件至少做一件和随意做,问value的最大值

思路:多组背包,分类讨论

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<sstream>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<set>
#include<vector>
using namespace std;
#define INF 0x3f3f3f3f
const int maxn=;
const double eps=1e-;
int c[],g[];
int dp[][];
int main()
{
int n,T,m,s,i,j,k;
while(~scanf("%d %d",&n,&T))
{
memset(dp,-,sizeof(dp));
memset(dp[],,sizeof(dp[]));
for(i=;i<=n;i++)
{
scanf("%d %d",&m,&s);
for(j=;j<m;j++)
scanf("%d%d",&c[j],&g[j]);
if(s==)
{
for(k=;k<m;k++)
for(j=T;j>=c[k];j--)
{
if(dp[i][j-c[k]]!=-)
dp[i][j]=max(dp[i][j],dp[i][j-c[k]]+g[k]);
if(dp[i-][j-c[k]]!=-)
dp[i][j]=max(dp[i][j],dp[i-][j-c[k]]+g[k]);
}
}
else if(s==)
{
for(j=;j<=T;j++)
dp[i][j]=dp[i-][j];
for(k=;k<m;k++)
for(j=T;j>=c[k];j--)
if(dp[i-][j-c[k]]!=-)
dp[i][j]=max(dp[i][j],dp[i-][j-c[k]]+g[k]);
}
else
{
for(j=;j<=T;j++)
dp[i][j]=dp[i-][j];
for(k=;k<m;k++)
for(j=T;j>=c[k];j--)
if(dp[i][j-c[k]]!=-)
dp[i][j]=max(dp[i][j],dp[i][j-c[k]]+g[k]);
}
}
cout<<dp[n][T]<<endl;
}
return ;
}

AreYouBusy HDU - 3535 (dp)的更多相关文章

  1. hdu 5534(dp)

    Input The first line contains an integer T indicating the total number of test cases. Each test case ...

  2. HDU 5800 (DP)

    Problem To My Girlfriend (HDU 5800) 题目大意 给定一个由n个元素组成的序列,和s (n<=1000,s<=1000) 求 :   f (i,j,k,l, ...

  3. hdu 5464(dp)

    题意: 给你n个数,要求选一些数(可以不选),把它们加起来,使得和恰好是p的倍数(0也是p的倍数),求方案数. - - 心好痛,又没想到动规 #include <stdio.h> #inc ...

  4. HDU 2571(dp)题解

    命运 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...

  5. Find a path HDU - 5492 (dp)

    Find a path Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  6. 饭卡 HDU - 2546(dp)

    电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额.如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后卡上余额为负),否则无法购买(即使金额足够).所以大家 ...

  7. HDU 4489(DP)

    http://acm.hdu.edu.cn/showproblem.php?pid=4489 解题思路这里已经说的很清楚了: http://blog.csdn.net/bossup/article/d ...

  8. hdu 1024(dp)

    传送门:Max Sum Plus Plus 题意:从n个数中选出m段不相交的连续子段,求这个和最大. 分析:经典dp,dp[i][j][0]表示不取第i个数且前i个数分成j段达到的最优值,dp[i][ ...

  9. HDU 2577(DP)

    题意:要求一个字符串输入,按键盘的最少次数.有Caps Lock和Shift两种转换大小写输入的方式 思路:用dpa与dpb数组分别记录Caps Lock的开关状态,dpa表示不开,dpb表示开 代码 ...

随机推荐

  1. 055 Jump Game 跳跃游戏

    给定一个非负整数数组,您最初位于数组的第一个索引处.数组中的每个元素表示您在该位置的最大跳跃长度.确定是否能够到达最后一个索引.示例:A = [2,3,1,1,4],返回 true.A = [3,2, ...

  2. Linux清空屏幕和清空当前输入的快捷键

    Linux清空屏幕和清空当前输入的快捷键 但是实际上...放弃当前的命令,命令行提示符跳到下一行的有效命令是ctrl + c

  3. python学习《一》

    从词篇博客开始,记录python3.0学习笔记 python3里    字符串用双引号,或者单引号,包起来 3双引号和3单引号   代表换行

  4. 【持续更新】Java 字符串相关问题

    区别 String s1="xxx" 与 String s2=new String("xxx") 的区别 equals() 和 == 的区别 单引号与双引号的区 ...

  5. sql 2008 中不能创建数据库关系图

    执行以下命令: ALTER AUTHORIZATION ON DATABASE::[databasename] TO sa [databasename] 为数据库名: 此方法借鉴于<老高> ...

  6. Java面向对象(类、封装)

    面向对象 今日内容介绍 u 面向对象 u 封装 第1章 面向对象 1.1 理解什么是面向过程.面向对象 面向过程与面向对象都是我们编程中,编写程序的一种思维方式. l 面向过程的程序设计方式,是遇到一 ...

  7. 解决easyUI下拉控件无法触发onkeydown事件

    实现在combotree下拉控件中按Backspace键清除combotree选中的值 下面的代码无法获取到键盘事件 <input class="easyui-combotree&qu ...

  8. win10 vm 11 桥接模式配置

    1 保证你Vmware里面的虚拟机是关机状态 2 在本地连接 属性中 卸载VM 桥接协议 3 管理员身份运行VM ,编辑>虚拟网络编辑器 删除所有网卡,并且重新配置网络适配器 4 配置完成后,选 ...

  9. hadoop的shell总结

    ls命令(文件内容) 列出系统跟目录下的目录和文件 Hadoop fs -ls / 列出文件系统所有的目录和文件 Hadoop fs -ls -R / cat命令(列出文档内容) Hadoop fs ...

  10. UVA 12673 Erratic Expansion 奇怪的气球膨胀 (递推)

    不难发现,每过一个小时,除了右下方的气球全都是蓝色以外,其他都和上一个小时的气球是一样的,所以是可以递推的.然后定义一类似个前缀和的东西f(k,i)表示k小时之后上面i行的红气球数.预处理出k小时的红 ...