Gold miner
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 132 Accepted Submission(s): 74
![](http://acm.hdu.edu.cn/data/images/C402-1003-1.jpg)
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.
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)
#include<stdio.h>
#include<algorithm>
using namespace std;
#define MAX(a,b) (a>b?a:b)
int N,T;
int cnt;
int num[205];
int visit[205];
int f[41000];
struct point //存放点的信息;
{
int x,y;
int t,v;
bool operator <(const point &A) const //运算符重载;相当于cmp(point A,point B){return abs(A.x)<abs(B.x);}
{
return abs(x)<abs(A.x);
}
}p[205];
struct node //存放共线的点;
{
int v[205]; //第几个点;
}Line[205];
struct pnode //存放共线点的t和v;
{
int weight[205];
int price[205];
}px[205];
int solve()
{
memset(f,0,sizeof(f)); //表示背包不需要装满;
for(int i=0;i<cnt;i++) //组数;
{
for(int v=T;v>=0;v--) //将每一个分组当作一次01背包,故v递减;
{
for(int k=0;k<num[i];k++) //每个分组中的成员;
{
if(v-px[i].weight[k]>=0)
f[v]=MAX(f[v],f[v-px[i].weight[k]]+px[i].price[k]);
}
}
}
return f[T];
}
int main()
{
int aa=1;
while(scanf("%d%d",&N,&T)!=-1)
{
cnt=0;
for(int i=1;i<=N;i++)
scanf("%d%d%d%d",&p[i].x,&p[i].y,&p[i].t,&p[i].v);
sort(p+1,p+N+1);
memset(num,0,sizeof(num));
memset(visit,0,sizeof(visit));
//判断是否共线;
for(int i=1;i<=N;i++)
{
int flag=0;
int x,y;
x=p[i].x;
y=p[i].y;
if(!visit[i])
{
Line[cnt].v[num[cnt]++]=i;
flag=1;
}
else
continue;
for(int j=i+1;j<=N;j++)
{
int x1=p[j].x;
int y1=p[j].y;
if(!visit[j]&&x*y1==x1*y)
{
visit[j]=1;
Line[cnt].v[num[cnt]++]=j;
}
}
if(flag)
cnt++;
}
for(int i=0;i<cnt;i++)
{
int a=0,b=0;
for(int j=0;j<num[i];j++)
{
int temp=Line[i].v[j];
a+=p[temp].t;
b+=p[temp].v;
px[i].weight[j]=a;
px[i].price[j]=b;
}
}
printf("Case %d: %d\n",aa++,solve());
}
return 0;
}