HDU 5188 背包
有N道题。要求得到最少W分
给出N道题的:每道题用时T。分数V,应在且必须在L时刻提交才干得分
问得到W分所用的最少的时间
以L-T排序,然后做01背包就可以
#include "stdio.h"
#include "algorithm"
#include "string.h"
using namespace std; struct Mark
{
int t,v,l,x;
}mark[40]; int dp[300010]; bool cmp(Mark a,Mark b)
{
if (a.x!=b.x) return a.x<b.x;
return a.l<b.l;
}
int Max(int a,int b)
{
if (a<b) return b;
else return a;
}
int main()
{
int n,m,i,j,ans,up,sum,sum1;
while (scanf("%d%d",&n,&m)!=EOF)
{
sum=sum1=up=0;
for (i=1;i<=n;i++)
{ scanf("%d%d%d",&mark[i].t,&mark[i].v,&mark[i].l);
sum+=mark[i].v;
sum1+=mark[i].t;
up=Max(up,mark[i].l);
mark[i].x=mark[i].l-mark[i].t;
}
if (sum<m) {printf("zhx is naive!\n"); continue;}
up=Max(up,sum1);
sort(mark+1,mark+n+1,cmp);
memset(dp,0,sizeof(dp));
for (i=1;i<=n;i++)
for (j=up;j>=mark[i].l ;j--)
dp[j]=Max(dp[j],dp[j-mark[i].t]+mark[i].v); ans=up+1;
for (i=0;i<=up;i++)
if (dp[i]>=m) {ans=i;break;}
if(ans==up+1) printf("zhx is naive!\n");
else printf("%d\n",ans);
}
return 0;
}
HDU 5188 背包的更多相关文章
- hdu 5188 zhx and contest [ 排序 + 背包 ]
传送门 zhx and contest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- hdu 5188(带限制的01背包)
zhx and contest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- HDU 5188 zhx and contest(带限制条件的 01背包)
Problem Description As one of the most powerful brushes in the world, zhx usually takes part in all ...
- HDU 1171 背包
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HDU 1171 Big Event in HDU 多重背包二进制优化
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1171 Big Event in HDU Time Limit: 10000/5000 MS (Jav ...
- hdu 0-1背包
题目地址http://acm.hdu.edu.cn/showproblem.php?pid=2602 #include <stdio.h> #include <string.h> ...
- hdu 01背包汇总(1171+2546+1864+2955。。。
1171 题意比较简单,这道题比较特别的地方是01背包中,每个物体有一个价值有一个重量,比较价值最大,重量受限,这道题是价值受限情况下最大,也就值把01背包中的重量也改成价值. //Problem : ...
- HUD 1171 Big Event in HDU(01背包)
Big Event in HDU Problem Description Nowadays, we all know that Computer College is the biggest depa ...
- H - Partial Tree HDU - 5534 (背包)
题目链接: H - Partial Tree HDU - 5534 题目大意:首先是T组测试样例,然后n个点,然后给你度数分别为(1~n-1)对应的不同的权值,然后问你在这些点形成树的前提下的所能形 ...
随机推荐
- 北京师范大学第十五届ACM决赛-重现赛
Another Server 时间限制:1秒 空间限制:262144K 题目描述 何老师某天在机房里搞事情的时候,发现机房里有n台服务器,从1到n标号,同时有2n-2条网线,从1到2n-2标号,其中第 ...
- hdu2042
#include <stdio.h> int main(){ int t,i,n,res; while(~scanf("%d",&t)){ while(t--) ...
- js对文字进行编码
js对文字进行编码涉及3个函数:escape,encodeURI,encodeURIComponent,相应3个解码函数:unescape,decodeURI,decodeURIComponent 1 ...
- 九度oj 题目1109:连通图
题目描述: 给定一个无向图和其中的所有边,判断这个图是否所有顶点都是连通的. 输入: 每组数据的第一行是两个整数 n 和 m(0<=n<=1000).n 表示图的顶点数目,m 表示图中边的 ...
- mysql5.7.23版本安装教程
亲身实践安装mysql,用时居然花费了三个小时,在有那么多教程的情况下,依然在不该花费时间的路上浪费了太多时间.希望这篇文章能够帮助大家少走弯路~~ 1.下载我下载的是64位. 2.解压下载之后,我选 ...
- 【线段树查询区间最值】poj 3264 Balanced Lineup
#include<cstdio> #include<algorithm> using namespace std; ; struct Seg { int l,r,mi,ma; ...
- LightOJ1125 Divisible Group Sums
Divisible Group Sums Given a list of N numbers you will be allowed to choose any M of them. So you c ...
- java.util.ResourceBundle 用法小介
java中读取配置文件的信息可以采用properties这个类,但是当遇到国际化问题的时候还是不好解决,因而还是最好使用 ResourceBundle这个类,其实ResourceBundle本质上和P ...
- BZOJ4726: [POI2017]Sabota?
$n \leq 500000$的树,开始有一个点是坏的,如果一个子树中坏点比例(不包括根节点)超过x那这整棵子树就会变坏,问最坏情况下不超过$K$个坏点的情况下$x$最小是多少. 被坑成傻逼.. 可以 ...
- Linux主机被SSH精神病(Psychos)暴力攻破后成为肉鸡的攻防过程
近日公司局域网突然变得非常慢,上网受到很大影响,不仅仅是访问互联网慢,就连访问公司内部服务器都感到异常缓慢.于是对本局域网网关进行测试: $ ping 10.10.26.254 发现延时很大, ...