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)对应的不同的权值,然后问你在这些点形成树的前提下的所能形 ...
随机推荐
- numpy.clip(a, a_min, a_max, out=None)(values < a_min are replaced with a_min, and those > a_max with a_max.)
numpy.clip(a, a_min, a_max, out=None) Clip (limit) the values in an array. Given an interval, values ...
- BZOJ 3295 [Cqoi2011]动态逆序对 ——CDQ分治
时间.位置.数字为三个属性. 排序时间,CDQ位置,树状数组处理数字即可. #include <cstdio> #include <cstring> #include < ...
- P1754 球迷购票问题 (卡特兰数,递推)
题目背景 盛况空前的足球赛即将举行.球赛门票售票处排起了球迷购票长龙. 按售票处规定,每位购票者限购一张门票,且每张票售价为50元.在排成长龙的球迷中有N个人手持面值50元的钱币,另有N个人手持面值1 ...
- asp.net 错误 类型"xxxxx"同时存在于"xxx.dll"和"xxxx.dll" 中
http://walttoney.blog.163.com/blog/static/127685797201051112839328/错误 类型“System.Web.UI.ScriptManager ...
- mode(BZOJ 2456)
Description 给你一个n个数的数列,其中某个数出现了超过n div 2次即众数,请你找出那个数. Input 第1行一个正整数n.第2行n个正整数用空格隔开. Output 一行一个正整数表 ...
- EC++学习笔记(六) 继承和面向对象设计
条款32:确定你的 public 继承塑模出 is-a 关系 public inheritance 意味着 is-a 关系class Derived 以 public 形式继承 class Base, ...
- Android 瘦身之道
Android 瘦身之道 ---- so文件 [TOC] 1. 前言 目前Android 瘦身只有几个方面可以入手,因为apk的结构就已经固定了. res 目录下的资源文件.(通常是压缩图片,比如 矢 ...
- 【C++】DLL内共享数据区在进程间共享数据(重要)
因项目需要,需要在DLL中共享数据,即DLL中某一变量只执行一次,在运行DLL中其他函数时该变量值不改变:刚开始想法理解错误,搜到了DLL进程间共享数据段,后面发现直接在DLL中定义全局变量就行,当时 ...
- golang-random随机数
在Golang中,有两个包提供了rand,分别为 "math/rand" 和 "crypto/rand", 对应两种应用场景. 一."math/ra ...
- Flink的安装配置
一. Flink的下载 安装包下载地址:http://flink.apache.org/downloads.html ,选择对应Hadoop的Flink版本下载 [admin@node21 soft ...