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. NET Core 2.0 自定义

    ASP.NET Core 2.0 自定义 _ViewStart 和 _ViewImports 的目录位置 在 ASP.NET Core 里扩展 Razor 查找视图目录不是什么新鲜和困难的事情,但 _ ...

  2. java课后思考问题(七)

    1.继承条件下的构造方法调用 package parent;class Grandparent { public Grandparent() { System.out.println("Gr ...

  3. git 本地新建分支Push到远程

    1. 本地新建分支,并切换到新的分支 git branch local_branch; git checkout local_branch; 2.第一条的命令也可以简单的一条命令来替代 git che ...

  4. DialogHelper

    //require ScrollHelper.js function DialogHelper() { var _this = this; var doc = window.document; _th ...

  5. 一般处理程序aspx

    public bool IsReusable { get { return false; } }属性,将该属性的值改为true,为什么不起作用?按照MSDN的解释,该属性的意思是: “获取一个值,该值 ...

  6. 获取url的参数值

    var url=location.search; //获取url中从?开始的所有字符 var  theRequest=new Object();//定义一个对象来存放url中的参数 if( url.i ...

  7. 登录控制 BaseController

    执行方法前 判断 sessin 登录信息 是否为空 ,空的话 返回 登录界面 并且给 LoginUser 赋值 public abstract class BaseController : Contr ...

  8. 微信成为HTML5技术流行的最大推手

    很多热点的事件都是厚积薄发,HTML5就是如此.此前iOS和Android系统已经放弃了Flash,这让HTML5有了一个天然的成长基础.而现在手机硬件的提升和HTML5本身的完善,使得基于HTML5 ...

  9. WinForm form属性

    一.布局 Autostroll   控件内容大于可见区域是否自动显示滚动条 Maximumsize 窗体可调到最大尺寸 minimumsize  窗体可调到最小尺寸 size  窗体看到的尺寸 Sta ...

  10. vue 文件流下载xlsx 功能实现

    downLoadFile (url, name) { this.xhr = new XMLHttpRequest() this.xhr.open('GET', url, true) this.xhr. ...