zhx and contest

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 455    Accepted Submission(s): 158

Problem Description
As one of the most powerful brushes in the world, zhx usually takes part in all kinds of contests.

One day, zhx takes part in an contest. He found the contest very easy for him.

There are n problems
in the contest. He knows that he can solve the ith problem
in ti units
of time and he can get vi points.

As he is too powerful, the administrator is watching him. If he finishes the ith problem
before time li,
he will be considered to cheat.

zhx doesn't really want to solve all these boring problems. He only wants to get no less than w points.
You are supposed to tell him the minimal time he needs to spend while not being considered to cheat, or he is not able to get enough points. 

Note that zhx can solve only one problem at the same time. And if he starts, he would keep working on it until it is solved. And then he submits his code in no time.
 
Input
Multiply test cases(less than 50).
Seek EOF as
the end of the file.

For each test, there are two integers n and w separated
by a space. (1≤n≤30, 0≤w≤109)

Then come n lines which contain three integers ti,vi,li.
(1≤ti,li≤105,1≤vi≤109)
 
Output
For each test case, output a single line indicating the answer. If zhx is able to get enough points, output the minimal time it takes. Otherwise, output a single line saying "zhx is naive!" (Do not output quotation marks).
 
Sample Input
1 3
1 4 7
3 6
4 1 8
6 8 10
1 5 2
2 7
10 4 1
10 2 3
 
Sample Output
7
8
zhx is naive!
 
Source
 

/* ***********************************************
Author :CKboss
Created Time :2015年03月19日 星期四 10时26分15秒
File Name :HDOJ5188.cpp
************************************************ */ #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map> using namespace std; const int maxn=200100; int n,w;
int sumtime,sumv;
int dp[maxn*30]; struct PB
{
int t,v,l;
}pb[50]; bool cmp(PB a,PB b)
{
return a.l-a.t<b.l-b.t;
} int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout); while(scanf("%d%d",&n,&w)!=EOF)
{
sumv=0;
for(int i=0;i<n;i++)
{
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
pb[i]=(PB){x,y,z};
sumv+=y;
}
if(sumv<w)
{
puts("zhx is naive!");
continue;
} sort(pb,pb+n,cmp);
memset(dp,0,sizeof(dp));
for(int i=0;i<n;i++)
for(int j=maxn;j>=max(pb[i].t,pb[i].l);j--)
dp[j]=max(dp[j],dp[j-pb[i].t]+pb[i].v); int ans=0;
for(int i=0;i<maxn;i++)
if(dp[i]>=w) { ans=i; break; } printf("%d\n",ans);
} return 0;
}

版权声明:来自: 代码代码猿猿AC路 http://blog.csdn.net/ck_boss

HDOJ 5188 zhx and contest 贪婪+01背包的更多相关文章

  1. HDOJ(HDU).3466 Dividing coins ( DP 01背包 无后效性的理解)

    HDOJ(HDU).3466 Dividing coins ( DP 01背包 无后效性的理解) 题意分析 要先排序,在做01背包,否则不满足无后效性,为什么呢? 等我理解了再补上. 代码总览 #in ...

  2. HDOJ(HDU).2546 饭卡(DP 01背包)

    HDOJ(HDU).2546 饭卡(DP 01背包) 题意分析 首先要对钱数小于5的时候特别处理,直接输出0.若钱数大于5,所有菜按价格排序,背包容量为钱数-5,对除去价格最贵的所有菜做01背包.因为 ...

  3. HDOJ(HDU).2602 Bone Collector (DP 01背包)

    HDOJ(HDU).2602 Bone Collector (DP 01背包) 题意分析 01背包的裸题 #include <iostream> #include <cstdio&g ...

  4. hdu 5188 zhx and contest [ 排序 + 背包 ]

    传送门 zhx and contest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  5. ZOJ 3703 Happy Programming Contest(0-1背包)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3703 Happy Programming Contest Time Lim ...

  6. HDOJ 1203 I NEED A OFFER!(01背包)

    10397507 2014-03-25 23:30:21 Accepted 1203 0MS 480K 428 B C++ 泽泽 题目链接:http://acm.hdu.edu.cn/showprob ...

  7. Gym 101102A Coins -- 2016 ACM Amman Collegiate Programming Contest(01背包变形)

    A - Coins Time Limit:3000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Descript ...

  8. 饭卡------HDOJ杭电2546(还是01背包!!!!!!)

    Problem Description 电子科大本部食堂的饭卡有一种非常诡异的设计,即在购买之前推断剩余金额. 假设购买一个商品之前,卡上的剩余金额大于或等于5元,就一定能够购买成功(即使购买后卡上剩 ...

  9. HDU 5188 zhx and contest(带限制条件的 01背包)

    Problem Description As one of the most powerful brushes in the world, zhx usually takes part in all ...

随机推荐

  1. zoj3329(概率dp)

    题目连接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3754 题意:有三个骰子,分别有k1,k2,k3个面. 每次掷骰子,如 ...

  2. hdu1160(最长上升子序列)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 题意:给定一些小猫的属性:体重和速度.然后求某些猫顺序的排列,使得体重上升,速度下降,这样的排列 ...

  3. 三点半们耐热i哦好家哦i囧囧【

    http://pan.baidu.com/share/link?shareid=3011665141&uk=338692646&third=15                http ...

  4. JVM指令集(指令码、助记符、功能描述)(转)

    JVM指令集(指令码.助记符.功能描述) 指令码 助记符 功能描述 0x00 nop 无操作 0x01 aconst_null 指令格式:  aconst_null 功能描述:  null进栈. 指令 ...

  5. Resource temporarily unavailable用户的连接数设置的太小

    -bash:fork:Resource temporarily unavailable的问题   出现这个问题的原因是linux用户的连接数设置的太小,只要修改max user processes就可 ...

  6. Effective C++:条款28:避免返回 handles 指向对象内部成员

    (一) 有时候为了让一个对象尽量小,能够把数据放在另外一个辅助的struct中,然后再让一个类去指向它.看以下的代码: class Point { public: Point(int x, int y ...

  7. SharePoint采用BCS开发第一个应用程序(两)

    SharePoint采用BCS开发第一个应用程序(两) 创建外部数据源 在本章中,我们使用AdventureWorksLT2008 SQL Server数据库作为外部数据源.下图显示了表SalesLT ...

  8. 基于.net开发chrome核心浏览器【一】

    原文:基于.net开发chrome核心浏览器[一] 说明: 这是本系列的第一篇文章,我会尽快发后续的文章. 源起 1.加快葬送IE6浏览器的进程 世界上使用IE6浏览器最多的地方在中国 中国使用IE6 ...

  9. WPF中不规则窗体与WebBrowser控件的兼容问题解决办法

    原文:WPF中不规则窗体与WebBrowser控件的兼容问题解决办法 引言 这几天受委托开发一个网络电视项目,要求初步先使用内嵌网页形式实现视频播放和选单,以后再考虑将网页中的所有功能整合进桌面程序. ...

  10. 可兼容IE的jquery.cookie函数方法

    前言 在开发过程中,因为之前有接触过Discuz,就直接拿其common.js里面的getcookie和setcookie方法来使用,做到后面在使用IE来测试的时候,发现这两个方法子啊IE下不起作用, ...