AreYouBusy HDU - 3535 (dp)

时间:2022-03-21 00:56:15

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. Normalize&period;css – 现代 Web 开发必备的 CSS resets

    Normalize.css 是一个可定制的 CSS 文件,使浏览器呈现的所有元素,更一致和符合现代标准.它正是针对只需要统一的元素样式.该项目依赖于研究浏览器默认元素风格之间的差异,精确定位需要重置的 ...

  2. webApi文档好帮手-apidoc使用教程

    来源:http://blog.csdn.net/xumin198908/article/details/41964159 在开发后台接口的过程中,我们肯定要提供一份api接口文档给终端app. 目前大 ...

  3. 第三十九篇、NavBar动态隐藏、设置透明、毛玻璃效果

    1.动态隐藏 - (void)viewDidLoad { [super viewDidLoad]; if ([self respondsToSelector:@selector(automatical ...

  4. &OpenCurlyDoubleQuote;有箭头的视图”,即程序的Storyboard Entry Point。

    设置方法很简单:打开StoryBoard文件,选中要设置为第一视图的ViewController,在右边工具栏勾选Is Initial View Controller就好了,此时你会看到ViewCon ...

  5. Oracle存储过程Procedure语法及案例

    create or replace procedure replace(desstr in varchar2, replacestr in varchar2, tablename in varchar ...

  6. html5脚本编程

    (1)跨文档消息传递,XDM.指的是来自不同域的页面间传递消息. XDM的核心是postMessage();向另一个地方传递数据,指是包含在当前页面中的iframe元素,由当前页面弹出的窗口. var ...

  7. Azure经典门户创建VM,如何设置使用静态IP地址?

    使用 Azure 经典管理门户中创建的虚拟机,无法使用静态IP 地址,在管理界面没有该设置.在新的管理门户中虽然有使用静态IP的设置,但是选项是灰色,无法修改,提示错误:This virtual ma ...

  8. 转:java泛型

    1.为什么需要泛型 转载请注明出处:http://blog.csdn.net/seu_calvin/article/details/52230032 泛型在Java中有很重要的地位,网上很多文章罗列各 ...

  9. Django入门&lpar;一&rpar;

    官方网站: 点击 Django 项目是一个python定制框架,它源自一个在线新闻 Web 站点,于 2005 年以开源的形式被释放出来.Django 框架的核心组件有: 用于创建模型的对象关系映射 ...

  10. UVa 11461 - Square Numbers【数学,暴力】

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...