HDOJ 5188 zhx and contest 贪婪+01背包
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
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.
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)
1 3
1 4 7
3 6
4 1 8
6 8 10
1 5 2
2 7
10 4 1
10 2 3
7
8
zhx is naive!
/* ***********************************************
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背包的更多相关文章
- HDOJ(HDU).3466 Dividing coins ( DP 01背包 无后效性的理解)
HDOJ(HDU).3466 Dividing coins ( DP 01背包 无后效性的理解) 题意分析 要先排序,在做01背包,否则不满足无后效性,为什么呢? 等我理解了再补上. 代码总览 #in ...
- HDOJ(HDU).2546 饭卡(DP 01背包)
HDOJ(HDU).2546 饭卡(DP 01背包) 题意分析 首先要对钱数小于5的时候特别处理,直接输出0.若钱数大于5,所有菜按价格排序,背包容量为钱数-5,对除去价格最贵的所有菜做01背包.因为 ...
- HDOJ(HDU).2602 Bone Collector (DP 01背包)
HDOJ(HDU).2602 Bone Collector (DP 01背包) 题意分析 01背包的裸题 #include <iostream> #include <cstdio&g ...
- hdu 5188 zhx and contest [ 排序 + 背包 ]
传送门 zhx and contest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- ZOJ 3703 Happy Programming Contest(0-1背包)
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3703 Happy Programming Contest Time Lim ...
- 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 ...
- Gym 101102A Coins -- 2016 ACM Amman Collegiate Programming Contest(01背包变形)
A - Coins Time Limit:3000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Descript ...
- 饭卡------HDOJ杭电2546(还是01背包!!!!!!)
Problem Description 电子科大本部食堂的饭卡有一种非常诡异的设计,即在购买之前推断剩余金额. 假设购买一个商品之前,卡上的剩余金额大于或等于5元,就一定能够购买成功(即使购买后卡上剩 ...
- HDU 5188 zhx and contest(带限制条件的 01背包)
Problem Description As one of the most powerful brushes in the world, zhx usually takes part in all ...
随机推荐
- nyoj 130 同样的雪花 【哈希】
同样的雪花 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描写叙述 You may have heard that no two snowflakes are alike. ...
- SE 2014年4月14日
一. 概述BGP的特点 BGP协议是一种距离矢量协议,基于TCP的179端口,BGP协议不会动态的学习路由,只能将IGP协议学习到的或者静态路由注入到BGP中,成为BGP路由,BGP路由携带有丰富的路 ...
- COLORREF和COLOR和RGB的总结
一.COLORREF与RGB的相互转化 RGB(r,g,b)是一个宏 实际上它做得事是((COLORREF)(((BYTE)(r)|((WORD)((BYTE)(g))<<8))|(((D ...
- Android-它们的定义Notification
Android-它们的定义Notification 2014年4月26日 消息栏的消息,想必各位Android发烧友非常清楚知道是什么,比方我们下载了一个应用,它可能会定时推送些消息到我们的手机中. ...
- 从零开始学Xamarin.Forms(一) 概述
原文:从零开始学Xamarin.Forms(一) 概述 Xamarin 读 "ˈzæmərin",是一个基于开源项目mono的能够使用C#开发的收费的跨平台(iOS.And ...
- DESCryptoServiceProvider加密解密的简单使用例子
DES.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using S ...
- 染色法判断是否是二分图 hdu2444
用染色法判断二分图是这样进行的,随便选择一个点, 1.把它染成黑色,然后将它相邻的点染成白色,然后入队列 2.出队列,与这个点相邻的点染成相反的颜色 根据二分图的特性,相同集合内的点颜色是相同的,即 ...
- FS SIP呼叫的消息线程和状态机线程
THREAD 当收到一次呼叫的时候,FS会在TU层创建两个线程,一个线程为状态机线程,另外一个为消息线程.状态机线程通过switch_core_session_thread_launch创建,顾名思义 ...
- Ubuntu下安装vmware 9.0 + 注册码
先附上一些注册码到时使用: NA0UF-DUH00-QZHM0-MU17K-CC824 4F469-F024Q-CZ8R9-DL1N0-13C6W HF261-0HL40-FZX21-F9AQ2-0C ...
- Ibatis之3个不经常使用的Query方法
1.queryForObject /** * Executes a mapped SQL SELECT statement that returns data to populate * the su ...