标签:
Description
Input
Output
Sample Input
Sample Output
///1085422276 #include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <vector> #include <queue> #include <typeinfo> #include <map> typedef long long ll; using namespace std; #define inf 10000000 inline ll read() { ll x=0,f=1; char ch=getchar(); while(ch<‘0‘||ch>‘9‘) { if(ch==‘-‘)f=-1; ch=getchar(); } while(ch>=‘0‘&&ch<=‘9‘) { x=x*10+ch-‘0‘; ch=getchar(); } return x*f; } //*************************************************************** struct ss { int x,y,v,t; }p[2050]; vector<ss >belong[2050]; bool cmp(ss a,ss b) { if(a.y*b.x!=a.x*b.y) return a.y*b.x<a.x*b.y; else return a.y<b.y; } int dp[40005]; int main() { int oo=1; int n,m; while(scanf("%d%d",&n,&m)!=EOF) { memset(dp,0,sizeof(dp)); for(int i=1;i<=n;i++)belong[i].clear(); for(int i=1;i<=n;i++) { scanf("%d%d%d%d",&p[i].x,&p[i].y,&p[i].t,&p[i].v); } p[0].x=-1; p[0].y=-1; sort(p+1,p+n+1,cmp); int zu=0; for(int i=1;i<=n;i++) { if(i!=1&&p[i].y*p[i-1].x==p[i].x*p[i-1].y) { ss kk; kk.v=belong[zu][belong[zu].size()-1].v+p[i].v; kk.t=belong[zu][belong[zu].size()-1].t+p[i].t; belong[zu].push_back(kk); } else { ss kk; kk.v=p[i].v; kk.t=p[i].t; belong[++zu].push_back(kk); } } //cout<<3213121<<endl; for(int i=1;i<=zu;i++) { for(int j=m;j>=0;j--) { for(int k=0;k<belong[i].size();k++) { if(j>=belong[i][k].t) { dp[j]=max(dp[j],dp[j-belong[i][k].t]+belong[i][k].v); } } } } printf("Case %d: %d\n",oo++,dp[m]); } return 0; }
标签:
原文地址:http://www.cnblogs.com/zxhl/p/4746136.html