hdu 3535 混合背包
来源:互联网 发布:仓库用的软件 编辑:程序博客网 时间:2024/06/01 22:28
AreYouBusy
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4087 Accepted Submission(s): 1627
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)?
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 32 12 53 82 01 02 13 24 32 11 13 42 12 53 82 01 12 83 24 42 11 11 11 02 15 32 01 02 12 02 21 12 03 22 12 11 52 83 23 84 95 10
Sample Output
513-1-1
题意:
老板让小A做一些工作,有多个case
每个case以 n T 开始,n表示有多少类工作,T表示限制的时间
每一类工作以m S开头,m表示这一类里面有m种工作
s==0 表示至少要选择一种工作做
s==1 表示最多要选择一种工作做
s==2 表示可以任意选择工作去做
每一种工作有两个数字c g,c表示需要花多少时间,g表示可以得到多少点快乐数
求解在规定时间内完成老师给的任务,最大的快乐数
如若不能完成就输出-1
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int dp[110][110];int main(){ int n,t; //freopen("in.txt","r",stdin); while(scanf("%d%d",&n,&t)!=EOF) { int m,s; memset(dp,0,sizeof(dp)); for(int i=1;i<=n;i++){ scanf("%d%d",&m,&s); if(!s) for(int k=0;k<=t;k++) dp[i][k]=-1; else for(int k=0;k<=t;k++) dp[i][k]=dp[i-1][k]; int c,g; for(int j=1;j<=m;j++){ scanf("%d%d",&c,&g); for(int k=t;k>=c;k--){ if(s==0){ if(dp[i][k-c]!=-1) dp[i][k]=max(dp[i][k],dp[i][k-c]+g); if(dp[i-1][k-c]!=-1) dp[i][k]=max(dp[i][k],dp[i-1][k-c]+g); } else if(s==1){ if(dp[i-1][k]!=-1) dp[i][k]=max(dp[i][k],dp[i-1][k]); if(dp[i-1][k-c]!=-1) dp[i][k]=max(dp[i][k],dp[i-1][k-c]+g); } else{ if(dp[i-1][k]!=-1) dp[i][k]=max(dp[i][k],dp[i-1][k]); if(dp[i][k-c]!=-1) dp[i][k]=max(dp[i][k],dp[i][k-c]+g); if(dp[i-1][k-c]!=-1) dp[i][k]=max(dp[i][k],dp[i-1][k-c]+g); } } } } printf("%d\n",dp[n][t]); } return 0;}
0 0
- HDU 3535 混合背包
- HDU 3535 混合背包
- hdu 3535 混合背包
- hdu 3535 混合背包
- hdu 3535(混合背包问题)
- HDU 3535 AreYouBusy(混合背包)
- hdu 3535 AreYouBusy 混合背包
- hdu 3535 AreYouBusy 混合背包
- [HDU 3535] AreYouBusy 混合背包
- HDU - 3535 AreYouBusy(混合背包)
- hdu 3535 AreYouBusy 混合背包
- hdu 3535 分组背包+混合背包
- hdu 3535 AreYouBusy(混合分组背包)
- HDU 3535 AreYouBusy 经典混合背包
- HDU 3535 AreYouBusy 经典混合背包
- HDU 3535 AreYouBusy(混合背包)
- hdu 3535 经典混合分组背包
- hdu 3535 AreYouBusy 经典混合背包
- Java知识点列表
- 【数据库SQL】批量更新促发器游标的方法
- R语言:用微软的深度学习理解图片情感
- Android内存泄漏:谨慎使用getSystemService
- PHPWAMP开启php_stomp.dll的具体方式,php5.6开启stomp的图解过程
- hdu 3535 混合背包
- android 中单例toast工具类
- Mysql命令alter add:增加表的字段
- 决定开始写小说
- node.js基础入门-3
- Flask-Socketio 部分翻译
- 【数据库SQL】修复数据库BCP修复(导出导入的做法)
- 《iOS移动开发从入门到精通》图书连载13:for循环、while循环语句、repeat-while循环语句
- 【数据库SQL】数据库修复,DBCC(常规正常修复)