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. zookeeper 性能测试

    zookeeper压力测试:性能对比(3个节点,5个节点,7个节点 创建节点.删除节点.设置节点数据.读取节点数据性能及并发性能) 测试结果如下: 五次测试三节点结果: 创建100W节点用时:15.0 ...

  2. spring AOP的Pointcut注解报错

    error at ::0 can't find referenced pointcut spring使用的是4.1.0,在项目中直接复制旧的aspectjweave.jar报错了 然后换成aspect ...

  3. Qt之图形(转换)

    简述 QTransform类指定坐标系的2D转换,可以指定平移.缩放.扭曲(剪切).旋转或投影坐标系.绘制图形时,通常会使用. QTransform与QMatrix的不同之处在于,它是一个真正的3x3 ...

  4. 赵雅智_运用Bitmap和Canvas实现图片显示,缩小,旋转,水印

    上一篇已经介绍了Android种Bitmap和Canvas的使用,以下我们来写一个详细实例 http://blog.csdn.net/zhaoyazhi2129/article/details/321 ...

  5. iOS Code Sign error: Provisioning profile can&#39;t be found 解决方式

    出现error的过程:在执行另外一个xcode项目重置了code sign.回到原来的项目的时候出现这个error 修复方法: targe-build settings-code signing id ...

  6. wxWidgets笔记_1_linux环境下wxwidgets的安装与配置

    linux下wxwidgets环境的安装与配置 一.建立目标文件夹(自己定义) mkdir /opt/SCOTT 二.安装wxWidgets 1.wxWidgets版本号能够选用wxGTK-2.8.1 ...

  7. vue2.0-transition多个元素

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. caioj1443:第k小的数Ⅲ

    [传送门:caioj1443] 简要题意: 给出一颗n个点的树,给出每个点的权值,再给出n-1条边,有m个询问,每个询问输入x,y,k,输出第x节点到第y节点的路径上第k大的点 题解: 这是一道主席树 ...

  9. oh-my-zsh upgrade problem

    Oh-My-ZSH upgrade issue with bad substitution message   Any problem with automatic Oh-My-Zsh upgrade ...

  10. OPENCV(3) —— 对XML和YAML文件实现I/O 操作

    XML\YAML文件在OpenCV中的数据结构为FileStorage string filename = "I.xml"; FileStorage fs(filename, Fi ...