HDU4341——Gold miner(分组背包)

来源:互联网 发布:时时彩的的网络女孩 编辑:程序博客网 时间:2024/06/05 17:27

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 101 1 1 12 2 2 21 3 15 93 101 1 13 12 2 2 21 3 4 7
 

Sample Output
Case 1: 3Case 2: 7
 

Author
HIT
 

Source
2012 Multi-University Training Contest 5 
 

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]);}}






0 0
原创粉丝点击