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)对应的不同的权值,然后问你在这些点形成树的前提下的所能形 ...
随机推荐
- python 多线程、多进程、协程性能对比(以爬虫为例)
基本配置:阿里云服务器低配,单核2G内存 首先是看协程的效果: import requests import lxml.html as HTML import sys import time impo ...
- Leetcode 337.大家结舍III
打家劫舍III 在上次打劫完一条街道之后和一圈房屋后,小偷又发现了一个新的可行窃的地区.这个地区只有一个入口,我们称之为"根".除了"根"之外,每栋房子有且只有 ...
- sql自动审核工具-inception
[inception使用规范及说明文档](http://mysql-inception.github.io/inception-document/usage/)[代码仓库](https://githu ...
- jQuery中文文档
http://www.jquery123.com/ http://www.shifone.cc/
- 【DFS序+树状数组】HDU 3887 Counting Offspring
http://acm.hdu.edu.cn/showproblem.php?pid=3887 [题意] 给定一棵树,给定这棵树的根 对于每个结点,统计子树中编号比他小的结点个数 编号从小到大一次输出 ...
- Java面试通关要点
Java面试通关要点 2018-03-23 梁桂钊 占小狼的博客 占小狼的博客 占小狼的博客 微信号 whywhy_zj 功能介绍 Java进阶技术干货.实践分享,跟着狼哥一起学习JVM.性能调优,欢 ...
- jenkins执行自动化用例(详细、有用、mark 优先级高高高)
http://blog.sina.com.cn/s/blog_68f262210102vx8o.html 第七章 测试用例接入jenkins自动运行 ------Web自动化测试之Webdriver+ ...
- OI 数论整理
1.素数: 质数(prime number)又称素数,有无限个.一个大于1的自然数,除了1和它本身外,不能被其他自然数整除,换句话说就是该数除了1和它本身以外不再有其他的因数;否则称为合数. 2016 ...
- net2:类,事件与委托
原文发布时间为:2008-07-29 -- 来源于本人的百度文章 [由搬家工具导入] using System;using System.Data;using System.Configuration ...
- iOS常用三方库收集
除非Pod可以直接加载到工程中的外,收集一下 https://github.com/kejinlu/KKGestureLockView 好用的手势解锁