HDU 4341

来源:互联网 发布:网络食品经营管理办法 编辑:程序博客网 时间:2024/05/17 00:14

抱学长大腿练习赛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 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

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


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


妈的智障..同一条线应该按照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