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. HDU 4643 GSM 简单计算几何

    今天比赛的时候略坑, admin告诉我询问Q的个数不超过n^2, 赛后敲了个 O(Q*m^3)的复杂度,但这个复杂度常数比较低,可能在除以个小常数, 300ms过了,真心无语,数据应该水了吧,比赛的时 ...

  2. BT渗透工具使用学习笔记

    BT51.信息收集2.扫描工具3.漏洞发现4.社会工程学工具5.运用层攻击MSF6.局域网攻击7.密码破解8.维持访问一.DNS信息收集1.Dnsenum/pentest/enumeration/dn ...

  3. dia 在Linux(ubuntu)下无法输入中文的解决办法 .

    我是执行一下命令安装的 sudo apt-get install dia sudo apt-get install dia 打开软件后发现不能输入中文,网上搜索一圈后找到以下解决方案 sudo vim ...

  4. RAC优化大框架的分配(jumbo frame)

    RAC优化大框架的分配(jumbo frame) 首先讲讲MTU的概念:在网络通信中,有个MTU(Max Transmission Unit)的概念,即网络传输中最大帧的大小,这个值默认是1500By ...

  5. Struts2第一个工程helloStruts极其基本配置

    前面已经准备好了Struts-2.3.15,现在就可以直接搭建Struts2的工程了.前面http://blog.csdn.net/huangchnegdada/article/details/917 ...

  6. 通过 Jersey Http请求头,Http响应头,客户端 API 调用 REST 风格的 Web 服务

    原地址:http://blog.csdn.net/li575098618/article/details/47853263 Jersey 1.0 是一个开源的.可以用于生产环境的 JAX-RS(RES ...

  7. ubuntu下使用自带的openJDK查看java源码

    如题 Ubuntu自带的OpenJDK仅仅有jre环境,不提供源代码,所以我们还是须要去下载. JDK6:http://download.java.net/openjdk/jdk6/ JDK7:htt ...

  8. 关于AIX VG中 LV 的状态问题,LV STATE

    在数据库管理过程中常常遇见LV状态异常,而造成LV不能再次被使用的情况,那么AIX中LV的两种状态分别代表什么呢 如果是访问fs需要open,即创建文件系统并mount 文件系统LV STATE 才是 ...

  9. MySQL 触发器例子(两张表同步增加和删除)

    以下两个例子来自:http://www.cnblogs.com/nicholas_f/archive/2009/09/22/1572050.html实测有效,但是原帖的分隔符不正确,因此稍作修改.其中 ...

  10. hdu 5073 Galaxy(2014acm鞍山亚洲分部 C)

    主题链接:http://acm.hdu.edu.cn/showproblem.php? pid=5073 Galaxy Time Limit: 2000/1000 MS (Java/Others)   ...