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. USACO Section 4.3 Street Race(图的连通性+枚举)

    虽说是IOI'95,但是也是挺水的..for 第一问,n最大为50,所以可以直接枚举起点和终点之外的所有点,然后dfs判断是否连通:for 第二问,易知答案一定是第一问的子集,所以从第一问中的答案中枚 ...

  2. hdu 4455 Substrings(找规律&DP)

    Substrings Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  3. JQuery的Select操作集合

    jQuery获取Select选择的Text和Value:   语法解释: $("#select_id").change(function(){//code...}); //为Sel ...

  4. symfony2-不同bundle的entity的一对多关系

    重点:其实和普通一个bundle中一样,只是把entity地址写全就行. 例子: 表commentone (多方) 表shopone(一方) 在Userbundle中的Commentone实体对应关系

  5. jQuery.validationEngine前端验证

    引入相关文件: <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.js" type ...

  6. ngCookies模块

    Angular中ngCookies模块介绍 1.Cookie介绍 Cookie总是保存在客户端中,按在客户端中的存储位置,可分为内存Cookie和硬盘Cookie.内存Cookie由浏览器维护,保存在 ...

  7. Android 蓝牙开发(整理大全)

    Android蓝牙开发 鉴于国内Android蓝牙开发的例子很少,以及蓝牙开发也比较少用到,所以找的资料不是很全. (一): 由于Android蓝牙的通信都需要用到UUID,如果由手机发起搜索,当搜索 ...

  8. Sunday字符串匹配算法

    逛ACM神犇的博客的时候看到的这个神奇的算法 KMP吧,失配函数难理解,代码量长 BF吧,慢,很慢,特别慢. BM吧,我不会写... 现在看到了Sunday算法呀,眼前一亮,神清气爽啊. 字符串匹配算 ...

  9. 吃透C#集合~大话目录

    最近买了一本<C#数据结构>的书,这种书确实少见,一般的数据结构都是采用C,C++来实现的,C#可以说是稀有了,呵呵,书写的不错,把C#的核心Collections介绍了一个透彻,对于我来 ...

  10. Linux特殊权限:SUID、SGID、SBIT

    SUID:      只对二进制程序有效      执行者对于程序需要有x权限      在程序运行过程中,执行者拥有程序拥有者的权限      例如:      普通用户执行passwd命令.   ...