250人阅读 评论(0)

# 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.

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

0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：64684次
• 积分：3092
• 等级：
• 排名：第12333名
• 原创：255篇
• 转载：6篇
• 译文：0篇
• 评论：7条