HDU4341——Gold miner(分组背包)

Gold miner

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


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
 

Author
HIT
 

Source
 

Recommend
zhuyuanchen520
 



黄金矿工游戏

给你很多金块的位置和价值以及需要多长时间把金块拉上来。

问你最多能得到多少价值。

一眼看上去就看得出和背包问题类似,有价值有花费

唯一的不同是若金块在一条直线上则需要先把挡在前面的金块拉上来。

那么对于一条直线上的金块,把前面的金块时间和价值累加到后面的金块上面。然后就是一个裸的分组背包问题了。


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <queue>
using namespace std;
const double EPS=1e-8;
const int MAXN =50000;
const long long INF =0x3f3f3f3f3f3f3f;
typedef long long LL;
int dp[MAXN];
int n,T;
const int MAX=210;
double x[MAX],y[MAX];
int t[MAX],v[MAX];
double f[MAX];
int vis[MAX];
//vector <int> g[MAX];
int g[MAX][MAX];
int cnt[MAX];
int main(){
	int cas=1;
	while(scanf("%d%d",&n,&T)!=EOF){
		memset(dp,0,sizeof(dp));
		memset(vis,0,sizeof(vis));
		memset(cnt,0,sizeof(cnt));
		int tot=0;
		for(int i=0;i<n;i++){
			scanf("%lf%lf%d%d",x+i,y+i,t+i,v+i);
			f[i]=x[i]/y[i];
			int ok=1;
			for(int j=0;j<i;j++){
				if(fabs(f[i]-f[j])<EPS){
					if(ok){
						vis[i]=vis[j];
						g[vis[j]][cnt[vis[j]]++]=i;
						ok=0;
					}
					if(y[i]>y[j]){
						t[i]+=t[j];
						v[i]+=v[j];
					}
					else{
						t[j]+=t[i];
						v[j]+=v[i];
					}
				}
			}
			if(ok){
				tot++;
				g[tot][0]=i;
				vis[i]=tot;
				cnt[tot]++;
			}
		}
		for(int i=0;i<=tot;i++){
			for(int w=T;w>=0;w--){
				for(int k=0;k<cnt[i];k++){
					int temp=g[i][k];
					if(w>=t[temp])
						dp[w]=max(dp[w],dp[w-t[temp]]+v[temp]);
				}
			}
		}
		printf("Case %d: ",cas++);
		printf("%d\n",dp[T]);
	}
}






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值