HDU 4341

抱学长大腿练习赛2:B题

传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4341

Gold miner

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2121    Accepted Submission(s): 799


Problem Description
Homelesser likes playing Gold miners in class. He has to pay much attention to the teacher to avoid being noticed. So he always lose the game. After losing many times, he wants your help.

To make it easy, the gold becomes a point (with the area of 0). You are given each gold's position, the time spent to get this gold, and the value of this gold. Maybe some pieces of gold are co-line, you can only get these pieces in order. You can assume it can turn to any direction immediately.
Please help Homelesser get the maximum value.
 

Input
There are multiple cases.
In each case, the first line contains two integers N (the number of pieces of gold), T (the total time). (0<N≤200, 0≤T≤40000)
In each of the next N lines, there four integers x, y (the position of the gold), t (the time to get this gold), v (the value of this gold). (0≤|x|≤200, 0<y≤200,0<t≤200, 0≤v≤200)
 

Output
Print the case number and the maximum value for each test case.
 

Sample Input
  
  
3 10 1 1 1 1 2 2 2 2 1 3 15 9 3 10 1 1 13 1 2 2 2 2 1 3 4 7
 

Sample Output
  
  
Case 1: 3 Case 2: 7

题意:矿工挖金矿,给出每个金矿所在坐标以及时间和金钱,问给定时间内如何赚到最多的钱,同一条直线上的矿石只能拿第一个


题解:分组背包,一条线上的当成一组来做


妈的智障..同一条线应该按照y排列因为x可能等于0...因为这个WA了50分钟...排序也写错了...i,j也搞反了一次...代码难看死了....

//背包? 
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<functional>
#include<queue>
#include<vector>
#include<set>
#include<map>
using namespace std;
double x[205],y[205],d[205];
int mark[205],v[205],w[205],p[205][205],l[205],dp[50005];
int main()
{
	
	int i,j,jj,k,n,m,V,W;


	int kkk=1;
	while(~scanf("%d%d",&m,&n))
	{
		
		memset(mark,0,sizeof(mark));
		memset(l,0,sizeof(l));
		memset(dp,0,sizeof(dp));
		for(i=0;i<=200;i++)
			for(j=0;j<=200;j++)
				p[i][j]=0;
		for(i=1;i<=m;i++)
		{
			scanf("%lf%lf%d%d",&x[i],&y[i],&v[i],&w[i]);
			d[i]=x[i]/y[i];//y确定不是0哇。。。 
		}
		k=1;
		for(i=1;i<=m;i++)
			for(j=i+1;j<=m;j++)
				if(d[i]==d[j]) 
				{
					if(mark[i]==mark[j] && mark[i]==0)
					{
						mark[i]=mark[j]=k;
						p[k][l[k]]=i;
						l[k]++;
						p[k][l[k]]=j;
						l[k]++;
						k++;
					}
					else if(mark[i]!=0 && mark[j]==0) 
					{
						mark[j]=mark[i];
						p[mark[i]][l[mark[i]]]=j;
						l[mark[i]]++;
					}
					else if(mark[j]!=0 && mark[i]==0) 
					{
						mark[i]=mark[j];
						p[mark[j]][l[mark[j]]]=i;
						l[mark[j]]++;
					}
				}
		for(i=1;i<=m;i++)
			for(j=n;j>=v[i];j--)
				if(mark[i]==0) dp[j]=max(dp[j],dp[j-v[i]]+w[i]);
		int iii,jjj;
		for(i=1;i<k;i++)
		{
			for(iii=0;iii<l[i];iii++)
				for(jjj=0;jjj<l[i]-1-iii;jjj++)
				if(y[p[i][jjj]]>y[p[i][jjj+1]])
				{
					int ttt=p[i][jjj];
					p[i][jjj]=p[i][jjj+1];
					p[i][jjj+1]=ttt;
				}
			
			//sort(p[i],p[i]+l[i]);
			
			for(jj=n;jj>=0;jj--)
			{
				V=W=0;
				for(j=0;j<l[i];j++)
				{
					V+=v[p[i][j]];
					W+=w[p[i][j]];
					if(jj-V>=0)dp[jj]=max(dp[jj],dp[jj-V]+W);
				}
			}
		}
		printf("Case %d: %d\n",kkk,dp[n]);
		kkk++;
	} 
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值