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!
 

题意:

  1. 有n道题i题用时ti秒,得分vi,在li时间点之前不能做出来,并且一道题不能分开几次做(一旦開始做,必须在ti时间内把它做完)
  2. 问得到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背包)的更多相关文章

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

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

  2. hdu 5187 zhx's contest [ 找规律 + 快速幂 + 快速乘法 || Java ]

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

  3. HDOJ 5188 zhx and contest 贪婪+01背包

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

  4. hdu 5188(带限制的01背包)

    zhx and contest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  5. hdu 5187 zhx's contest (快速幂+快速乘)

    zhx's contest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) To ...

  6. HDU 3339 In Action(迪杰斯特拉+01背包)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=3339 In Action Time Limit: 2000/1000 MS (Java/Others) ...

  7. HDU 2602 Bone Collector 骨头收集者【01背包】

    题目链接:https://vjudge.net/contest/103424#problem/A 题目大意: 第一行输入几组数据,第二行第一个数字代表物体个数,第二个数代表总体积.需要注意的是,第三排 ...

  8. HDU 6083 度度熊的午饭时光(01背包+记录路径)

    http://acm.hdu.edu.cn/showproblem.php?pid=6083 题意: 思路: 01背包+路径记录. 题目有点坑,我一开始逆序枚举菜品,然后一直WA,可能这样的话路径记录 ...

  9. hdu 3466 Proud Merchants 自豪的商人(01背包,微变形)

    题意: 要买一些东西,每件东西有价格和价值,但是买得到的前提是身上的钱要比该东西价格多出一定的量,否则不卖.给出身上的钱和所有东西的3个属性,求最大总价值. 思路: 1)WA思路:与01背包差不多,d ...

随机推荐

  1. python IO编程-StringIO和BytesIO

    链接:https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/0014319187857 ...

  2. 洛谷——P1965 转圈游戏

    https://www.luogu.org/problem/show?pid=1965 题目描述 n 个小伙伴(编号从 0 到 n-1)围坐一圈玩游戏.按照顺时针方向给 n 个位置编号,从0 到 n- ...

  3. 警惕 InnoDB 和 MyISAM 创建 Hash 索引陷阱

    MySql 最经常使用存储引擎 InnoDB 和 MyISAM 都不支持 Hash 索引,它们默认的索引都是 B-Tree.可是假设你在创建索引的时候定义其类型为 Hash,MySql 并不会报错,并 ...

  4. 把握linux内核设计思想(三):下半部机制之软中断

    [版权声明:尊重原创.转载请保留出处:blog.csdn.net/shallnet,文章仅供学习交流,请勿用于商业用途]         中断处理程序以异步方式执行,其会打断其它重要代码,其执行时该中 ...

  5. hdu 3068 最长回文 【Manacher求最长回文子串,模板题】

    欢迎关注__Xiong的博客: http://blog.csdn.net/acmore_xiong?viewmode=list 最长回文                                 ...

  6. 对照 Android 的 Intent 与 iOS StoryBoard 的 Segue - Intent 假设也能添加个prepareForSegue回调就好了

    对照 Android 的 Intent 与 iOS StoryBoard 的 Segue - Intent 假设也能添加个prepareForSegue回调就好了 太阳火神的漂亮人生 (http:// ...

  7. Oracle 复制随意表一行的SQL语句(測试Ok)

    測试了非常久,网上说的方法非常多,事实上都是错误的.正确的写法: declare cursor rowAll is select * from tb_news where 1=1; row1 tb_n ...

  8. Oracle数据库备份恢复,巡检须要关注的对象设置以及相关恢复概述

    数据库备份恢复.巡检须要关注的对象设置: 1.数据库名称,以及DBID:  --dbid在v$database中     SYS@ORCL>select dbid,name from v$dat ...

  9. MVC页面常用方法

    转自:https://www.cnblogs.com/baisoft/p/5839319.html @RenderBody 在Razor引擎中没有了“母版页”,取而代之的是叫做“布局”的页面(_Lay ...

  10. Windows server 2016 解决“无法完成域加入,原因是试图加入的域的SID与本计算机的SID相同。”

    使用克隆的系统时,加域是出现如下问题.“无法完成域加入,原因是试图加入的域的SID与本计算机的SID相同.” 问题原因:Windows使用SID来表示所有的安全对象(security principa ...