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)对应的不同的权值,然后问你在这些点形成树的前提下的所能形 ...
随机推荐
- [BZOJ1419] Red is good(期望DP)
传送门 逆推 只不过顺序还是顺着的,思想是逆着的 f[i][j]表示还剩下i张红牌,j张黑牌的期望值 那么边界是 f[i][0]=i,因为只剩i张红牌 f[0][j]=0,只剩黑牌,显然直接停止最优 ...
- hdu 2100
#include<stdio.h> #include<string.h> char a[300],b[300]; int a1[300],b1[300]; int main() ...
- 【JQ同胞遍历】
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- XPath用法详解
1.XPath是什么 XPath 是一门在 XML 文档中查找信息的语言.XPath 用于在 XML 文档中通过元素和属性进行导航(你可以理解为一种类似正则表达式的方法) 2.XPath的语法 表达式 ...
- python--输出自己需要的字符串连接的的方式
python中有很多字符串连接方式,今天在写代码,顺便总结一下,从最原始的字符串连接方式到字符串列表连接,大家感受下: 最原始的字符串连接方式:str1 + str2 python 新字符串连接语法: ...
- android Containers控件
1.RadioGroup 一组单选框容器 2.ListView 3.GridView 4.ExpandableListView 可折叠列表 5.ScrollView 上下滚动条 6.Horizonta ...
- Redis数据库No-SQL的介绍安装和使用
Redis安装步骤 1.官网下载Redis压缩包http://download.redis.io/releases/redis-5.0.2.tar.gz,然后将下载的redis上传到虚拟机的/usr/ ...
- Hadoop安装和基本单机部署
下载安装 # 下载 $ cd /usr/local $ wget http://mirrors.hust.edu.cn/apache/hadoop/common/hadoop-2.9.2/hadoo ...
- 《深入理解mybatis原理》 MyBatis的二级缓存的设计原理
MyBatis的二级缓存是Application级别的缓存,它可以提高对数据库查询的效率,以提高应用的性能.本文将全面分析MyBatis的二级缓存的设计原理. 如上图所示,当开一个会话时,一个SqlS ...
- ASP.NET Core 依赖注入(构造函数注入,属性注入等)
原文:ASP.NET Core 依赖注入(构造函数注入,属性注入等) 如果你不熟悉ASP.NET Core依赖注入,先阅读文章: 在ASP.NET Core中使用依赖注入 构造函数注入 构造函数注 ...