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 ...
随机推荐
- Android清理设备内存具体完整演示样例(一)
MainActivity例如以下: package come.on; import android.app.Activity; import android.content.Context; impo ...
- Wix学习整理(5)——安装时填写注册表
原文:Wix学习整理(5)--安装时填写注册表 一 Microsoft操作系统的注册表 什么是注册表? 注册表是Mircrosoft Windows中的一个重要的数据库,用于存储系统和应用程序的设置信 ...
- 初尝Java序列化/反序列化对象
看个类: package com.wjy.bytes; import java.io.Serializable; public class ObjTest implements Serializabl ...
- poj2777--Count Color(线段树,二进制转化)
Count Color Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 34950 Accepted: 10542 Des ...
- 啊我V办我偶看篇未改片考i
http://pan.baidu.com/share/link?shareid=3011665141&uk=338692646&third=15 http ...
- leetcode -day19 Convert Sorted List to Binary Search Tree
1. Convert Sorted List to Binary Search Tree Given a singly linked list where elements are sorted ...
- WPF界面设计技巧(3)—实现不规则动画按钮
原文:WPF界面设计技巧(3)-实现不规则动画按钮 发布了定义WPF按钮的教程后,有朋友问能否实现不规则形状的按钮,今天我们就来讲一下不规则按钮的制作. 不规则按钮的做法实际上和先前我们做不规则窗体的 ...
- A Game of Thrones(3) - Daenerys
Her brother held the gown up for her inspection. “This is beauty. Touch it. Go on. Caress(爱抚,抚抱) the ...
- C/S与B/S谁与争锋之我见
看到网上有些人在讨论C/S架构和B/S架构以及它们的发展趋势,后起之秀B/S是否真将取代C/S而存在?在发表我的观点之前,我们先来一起来回顾下C/S以及B/S. 一C/S 1.C/S概念 C/S是Cl ...
- CentOS 如何使用第三方软件库-EPEL与RPMForge、RPMFusion软件库
在CentOS下运行yum install flash-plugin或yum install mplayer的时候,提示库里没有找到这个软件?为什么会这样?因为CentOS是RHEL编译过来的,去掉了 ...