HDU 5188 zhx and contest(带限制条件的 01背包)
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.
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)
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!
题意:
- 有n道题i题用时ti秒,得分vi,在li时间点之前不能做出来,并且一道题不能分开几次做(一旦開始做,必须在ti时间内把它做完)
- 问得到w分的最小用时是多少
思路: 把题目按開始做的先后顺序排序,然后o1背包
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map> #define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MID(x,y) ((x+y)>>1) #define eps 1e-8
typedef __int64 ll; #define fre(i,a,b) for(i = a; i <b; i++)
#define free(i,b,a) for(i = b; i >= a;i--)
#define mem(t, v) memset ((t) , v, sizeof(t))
#define ssf(n) scanf("%s", n)
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pf printf
#define bug pf("Hi\n") using namespace std; #define INF 0x3f3f3f3f
#define N 100005 int dp[30*N]; struct stud{
int t,l,va;
bool operator < (const stud a) const
{
return l-t<a.l-a.t;
} }f[40]; int all,sum;
int n,m; void solve()
{
int i,j; sort(f,f+n); int te; mem(dp,0); fre(i,0,n)
free(te,all,f[i].l)
if(te>=f[i].t)
dp[te]=max(dp[te],dp[te-f[i].t]+f[i].va); fre(i,0,all)
if(dp[i]>=m) break; pf("%d\n",i);
} int main()
{
int i,j;
while(~sff(n,m))
{
sum=all=0;
int temp=0; fre(i,0,n)
{
sfff(f[i].t,f[i].va,f[i].l);
all+=f[i].t;
temp=max(temp,f[i].l);
sum+=f[i].va;
} if(sum<m)
{
pf("zhx is naive!\n");
continue;
} all=max(all,temp);
solve();
}
return 0;
}
HDU 5188 zhx and contest(带限制条件的 01背包)的更多相关文章
- hdu 5188 zhx and contest [ 排序 + 背包 ]
传送门 zhx and contest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- hdu 5187 zhx's contest [ 找规律 + 快速幂 + 快速乘法 || Java ]
传送门 zhx's contest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- HDOJ 5188 zhx and contest 贪婪+01背包
zhx and contest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- hdu 5188(带限制的01背包)
zhx and contest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- hdu 5187 zhx's contest (快速幂+快速乘)
zhx's contest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) To ...
- HDU 3339 In Action(迪杰斯特拉+01背包)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=3339 In Action Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 2602 Bone Collector 骨头收集者【01背包】
题目链接:https://vjudge.net/contest/103424#problem/A 题目大意: 第一行输入几组数据,第二行第一个数字代表物体个数,第二个数代表总体积.需要注意的是,第三排 ...
- HDU 6083 度度熊的午饭时光(01背包+记录路径)
http://acm.hdu.edu.cn/showproblem.php?pid=6083 题意: 思路: 01背包+路径记录. 题目有点坑,我一开始逆序枚举菜品,然后一直WA,可能这样的话路径记录 ...
- hdu 3466 Proud Merchants 自豪的商人(01背包,微变形)
题意: 要买一些东西,每件东西有价格和价值,但是买得到的前提是身上的钱要比该东西价格多出一定的量,否则不卖.给出身上的钱和所有东西的3个属性,求最大总价值. 思路: 1)WA思路:与01背包差不多,d ...
随机推荐
- C++输入流
输出流基本概念 输出流定义在头文件中.大部分程序都会包含头文件,这个头文件又包含了输入流和输出流头文件.头文件还声明了标准控制台输出流cout. 使用输出流的最简单的方法是使用<<运算 ...
- centos的终端字体杂乱的问题
sudo yum -y install dejavu-sans-* dejavu-serif-fonts 下载字体一下就好了
- Error 0x80070020 when you try to start a Web site in IIS 7.0
https://support.microsoft.com/en-hk/help/973094/error-0x80070020-when-you-try-to-start-a-web-site-in ...
- syslog介绍-CS架构来采集系统日志
syslog架构 Unix/Linux系统中的大部分日志都是通过一种叫做syslog的机制产生和维护的.syslog是一种标准的协议,分为客户端和服务器端,客户端是产生日志消息的一方,而服务器端负责接 ...
- 数据库阿里连接池 Druid配置详解以及web监控统计
java程序很大一部分要操作数据库,为了提高性能操作数据库的时候,有不得不使用数据库连接池.数据库连接池有很多选择,c3p.dhcp.proxool等,druid作为一名后起之秀,凭借其出色的性能,也 ...
- impala 概述
impala 概述 什么是Impala? Impala是用于处理存储在Hadoop集群中的大量数据的MPP(大规模并行处理)SQL查询引擎. 它是一个用C ++和Java编写的开源软件. 与其他Had ...
- tensorflow学习之路---简单的代码
import numpyimport tensorflow as tf #自己创建的数据x_data = numpy.random.rand(100).astype(numpy.float32)#创建 ...
- 一个Web报表项目的性能分析和优化实践(五):重构有助于性能优化么?
项目从初次开发到现在,已经快3年了.期间,有N个工程师参与过. 需求方面:增加减少,反反复复,无数次:人力方面:增加减少,不稳定:时间方面:功能开发着急上线,Bug开发紧急修复. 因此,代码臃肿,问题 ...
- jQuery和JavaScript的点击事件区别
// $("#indexPage").click(); // 触发了a标签的点击事件,但是没有触发页面跳转 document.getElementById("indexP ...
- Windows操作系统下将Redis安装为服务
安装服务: E:/Redis/Redis-x64-3.2.100/redis-server.exe --service-install E:/Redis/Redis-x64-3.2.100/redis ...