首页 > 其他分享 >hdu 5188(限制01背包)

hdu 5188(限制01背包)

时间:2023-05-29 18:32:11浏览次数:41  
标签:hdu 01 int zhx 5188 time output dp he


zhx and contest



Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)




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


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!


 


解题思路:

最开始我的想法是按照l排序,然后就是简单的01背包,但WA。。。

这里需要按照l-t的大小进行排序才行。因为对于时间最少的方法,一定按照题目最早可以开始做的时间的顺序做,即按照l-t的从小到大顺序来做。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int maxn = 35;
struct Node
{
	int t,v,l;

	bool operator < (const Node prbm) const
	{
		return l - t < prbm.l - prbm.t;
	}
}p[maxn];
int n,w;
__int64 dp[3000005];

int main()
{
	while(scanf("%d%d",&n,&w)!=EOF)
	{
		int m = 0;
		memset(dp,0,sizeof(dp));
		for(int i = 1; i <= n; i++)
		{
			scanf("%d%d%d",&p[i].t,&p[i].v,&p[i].l);
			m += p[i].t;
		}
		sort(p+1,p+1+n);
		m += p[n].l;
		for(int i = 1; i <= n; i++)
			for(int j = m; j >= 0; j--)
			{
				if(j < p[i].l) break;
				if(j >= p[i].t)
					dp[j] = max(dp[j],dp[j-p[i].t] + p[i].v);
			}
		int ans = -1;
		for(int j = 0; j <= m; j++)
			if(dp[j] >= w)
			{
				ans = j;
				break;
			}
		if(ans == -1)
			printf("zhx is naive!\n");
		else printf("%d\n",ans);
	}
	return 0;
}




标签:hdu,01,int,zhx,5188,time,output,dp,he
From: https://blog.51cto.com/u_16143128/6373503

相关文章

  • hdu 5171(矩阵快速幂)
    GTY'sbirthdaygiftTimeLimit:2000/1000MS(Java/Others)    MemoryLimit:65536/65536K(Java/Others)ProblemDescriptiona,b∈S),andadda+b Input2≤n≤100000,1≤k≤1000000000).Thesecondlinecontainsnelementsai......
  • hdu 5157(manacher+前缀和+树状数组)
    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5157解题思路:我们可以先用mancher算法对字符串进行处理,把以每个点为中心的回文串半径求出来,然后进行处理。加入对以p为中心的点,从p-r[i]+1~p都是回文串的开头,那么对于每个回文串(开头是j)只要记录结尾从1~j-1的回文串个数,我们可......
  • 【Oracle】Oracle Database Administration 2019 Certified Professional Certificati
     说明:1.目前题库100%覆盖考题,准确率84%。2.若需要优质烤券,请私信,留下你的WX。(官方250刀,本店只需要1500RMB包含100%完整题库以及考试经验分享)3.本条信息长期有效。考试题量:85通过分数:84%1、WhichtwoaretrueaboutreclaimingspaceusedbyFlashbacklogsinOracle......
  • 【蓝桥杯 2019 省 A】修改数组【并查集】
    链接https://www.luogu.com.cn/problem/P8686题意给你\(n\)个数a[1...n],从\(a_2\)开始,如果和之前的某个数具有相等的值,就一直让\(a_i=a_i+1\),直到前面的任何一个数都和它不相等\(1\leqn\leq10^5\),\(1\leqa_i\leq10^6\)问最后的序列是什么思路暴力做法......
  • Flask013_ for 循环语句
    调用[email protected]('/for')2deffor_statement():3books=[{4'title':'三国演义',5'author':'罗贯中',6'price':1007},8{9'ti......
  • LOD技术的研究与应用——三维地质体-2012硕士论文
    作者:张彬摘要随着计算机科学的发展,工程上的一些数据表达形式更加丰富多彩,已经从原来二维表达逐步向三维表达迈进。三维能表达更多的信息,视觉上更清晰,更直观,能有效的帮助工程人员进行分析、预算、决策。目前不论是军事,电力,油田,还是企业,都将三维应用研究作为其研究的重点内容,三维......
  • sockjs.js:1603 GET http://localhost/sockjs-node/info?t=1685340190468 net::ER
    vue项目报错不影响运行,但控制台看到这报错,属实不舒服 解决方法:进入\node_modules\sockjs-client\dist\sockjs.js注释1603行   刷新页面,没报错了 ......
  • WPS2019集美大学版v11.8.6.11825
    软件介绍WPSOffice2019增强版(wps集美大学专用版)是一款由大学教育机构定制的WPS企业版,wps2019政府版拥有正版授权,免激活可以长期使用.金山Office办公软件最新wps2019专业增强版wps2019永久激活版下载.软件截图版本特点WPS2019集美大学专用版:免激活、去水印、永久授权、......
  • [AGC010B]Boxes
    AGC010BBoxes先将题目转换成正着的,即由全\(0\)变为给定的序列。操作次数为\(k=\dfrac{\suma_i}{n(n+1)\div2}\)。条件\(k\)必定是整数很显然。这道题的重点在于这个增加的数列是一个等差数列,考虑到这样差分数组十分方便,对\(a\)原地差分,设以\(i\)为起点做一次操作,进......
  • 2018算法课习题(一)
    目录:数字统计问题2011的倍数最多约数问题最大间隙问题字典序问题金币列阵问题更新中......问题B:数字统计问题(二)时间限制:1Sec  内存限制:128MB提交:8  解决:6[提交][状态][讨论版][命题人:admin]题目描述给定一本书,其中包含n页,计算出书的全部页码中用到了多少个......