http://acm.hdu.edu.cn/showproblem.php?

pid=5188

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!
/**
hdu5188 有限制条件的01背包问题
题目大意:有n道题i题用时ti秒,得分vi,在li时间点之前不能做出来,并且一道题不能分开几次做(一旦開始做,必须在ti时间内把它做完)
问得到w分的最小用时是多少
解题思路:非常像01背包的基本题,可是有一个li分钟前不能AC的限制,因此第i道题必须在最早第(li-ti)时刻做,我们依照l-t递增排序,然后依照经典解法来做
即可了
*/
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
using namespace std; struct note
{
int t,v,l;
bool operator <(const note &other)const
{
return l-t<other.l-other.t;
} }node[35]; int n,m;
int dp[3000005]; int main()
{
while(~scanf("%d%d",&n,&m))
{
int sum=0,ans=0,up=0;
for(int i=0;i<n;i++)
{
scanf("%d%d%d",&node[i].t,&node[i].v,&node[i].l);
sum+=node[i].v;
ans+=node[i].t;
up=max(up,node[i].l);
}
if(m>sum)
{
printf("zhx is naive!\n");
continue;
}
sort(node,node+n);
up=max(up,ans);
memset(dp,0,sizeof(dp));
for(int i=0;i<n;i++)
{
for(int j=up;j>=node[i].l;j--)
{
if(j>=node[i].t)
{
dp[j]=max(dp[j],dp[j-node[i].t]+node[i].v);
}
}
}
int flag=0;
for(int i=0;i<=up;i++)
{
if(dp[i]>=m)
{
printf("%d\n",i);
flag=1;
break;
}
}
if(flag==0)
{
printf("zhx is naive!\n");
}
}
return 0;
}
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!

hdu5188 加限制的01背包问题的更多相关文章

  1. 01背包问题(动态规划)python实现

    01背包问题(动态规划)python实现 在01背包问题中,在选择是否要把一个物品加到背包中.必须把该物品加进去的子问题的解与不取该物品的子问题的解进行比較,这样的方式形成的问题导致了很多重叠子问题, ...

  2. 算法笔记(c++)--01背包问题

    算法笔记(c++)--经典01背包问题 算法解释起来太抽象了.也不是很好理解,最好的办法就是一步步写出来. 背包问题的核心在于m[i][j]=max(m[i-1][j],m[i-1][j-w[i]]+ ...

  3. PAT 甲级 1068 Find More Coins (30 分) (dp,01背包问题记录最佳选择方案)***

    1068 Find More Coins (30 分)   Eva loves to collect coins from all over the universe, including some ...

  4. 0-1背包问题——回溯法求解【Python】

    回溯法求解0-1背包问题: 问题:背包大小 w,物品个数 n,每个物品的重量与价值分别对应 w[i] 与 v[i],求放入背包中物品的总价值最大. 回溯法核心:能进则进,进不了则换,换不了则退.(按照 ...

  5. 201871030138-杨蕊媛 实验二 个人项目—《D{0-1}背包问题》项目报告

    项目 内容 课程班级博客链接 https://edu.cnblogs.com/campus/xbsf/2018CST 这个作业要求链接 https://www.cnblogs.com/nwnu-dai ...

  6. 01背包问题:POJ3624

    背包问题是动态规划中的经典问题,而01背包问题是最基本的背包问题,也是最需要深刻理解的,否则何谈复杂的背包问题. POJ3624是一道纯粹的01背包问题,在此,加入新的要求:输出放入物品的方案. 我们 ...

  7. 01背包问题:Charm Bracelet (POJ 3624)(外加一个常数的优化)

    Charm Bracelet    POJ 3624 就是一道典型的01背包问题: #include<iostream> #include<stdio.h> #include& ...

  8. HDU 1864最大报销额 01背包问题

    B - 最大报销额 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit St ...

  9. HDOJ 2546饭卡(01背包问题)

    http://acm.hdu.edu.cn/showproblem.php?pid=2546 Problem Description 电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额.如 ...

随机推荐

  1. isalpha函数,判断字符是否是字母

    头文件:<iostream> or  <cctype>  在c语言中<ctype.h> 功能:判断一个字符是否是英文字符,是大写返回1,是小写返回2,不是英文字符返 ...

  2. DSP的cache一般在何时会生效,防止在cache使用造成数据不一致

    在使用DSP的cache使能所有的ddr操作时,发现如果只是写操作,根据cache的机制,如果没有在了L1级hit,则直接使用write buffer来完成写操作. 假如hit的话,那之前一定发生过读 ...

  3. PhpStorm 10.0 激活方式

    随着 JetBrains 新版本的发布,注册机已然不行了.然而,道高一尺,魔高一丈.IntelliJ IDEA开源社区 提供了如下通用激活方法:注册时选择License server填写http:// ...

  4. javascript 数组和字符串的转化

    字符串转化为数组 'abcde' -> ['a', 'b', 'c', 'd', 'e'] 简单一点的方法,__String.prototype.split__可以将字符串转化为数组,分隔符为空 ...

  5. Linux 安装g++

    g++ 它的全名不叫g++而是叫gcc-c++; 所以要安装它就可以用 yum install gcc-c++;

  6. Linux 硬盘、网卡

    根据硬盘接口的不同,在Liunx中会有不同的命名 IDE 接口的硬盘会被叫成: hda,hdb,hdc (hd -- hard disk) hda 表示第一块硬盘,hdb表示第二块硬盘! 一般来说我们 ...

  7. node 上传文件 路径 重命名等问题

    最近在学习node,想做一个简单的网站.首先想到的是上传文件的功能,查了下,发现有一个formidable模块,操作方便,便拿来尝试了一下,结果很纠结. 下载安装的就不用说了,用npm即可.说一下,自 ...

  8. 解决Flex4 发布后访问 初始化极其缓慢的问题

    原文http://blog.163.com/vituk93@126/blog/static/170958034201282222046364/ 昨天找了个免费.net空间,想测试一下做的一个简单Fle ...

  9. cpan安装及其使用

    cpan安装及其使用 Perl是一种相当灵活的程序编程语言,现有的许有程序都是使用它进行编程的.它的优点之一就是无需自己编写编码,你就能利用许多增加的模块,创建新的功能. 程序利用这些模块的编码,而程 ...

  10. POJ 3723 Conscription(并查集建模)

    [题目链接] http://poj.org/problem?id=3723 [题目大意] 招募名单上有n个男生和m个女生,招募价格均为10000, 但是某些男女之间存在好感,则招募的时候, 可以降低与 ...