标签:ring lock alt cep 限制 scan 比较 rmi input
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 5599 Accepted Submission(s): 2362
A:p1,q1 B: p2,q2,先选A,则至少需要p1+q2的容量,而先选B则至少需要p2+q1,如果p1+q2>p2+q1,那么要选两个的话的就要先选A再选B,公式可换成q1-p1 < q2-p2,
// // main.cpp // hdu3466 // // Created by Candy on 29/10/2016. // Copyright © 2016 Candy. All rights reserved. // #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <queue> using namespace std; const int N=505,M=5005; inline int read(){ char c=getchar();int x=0,f=1; while(c<‘0‘||c>‘9‘){if(c==‘-‘)f=-1; c=getchar();} while(c>=‘0‘&&c<=‘9‘){x=x*10+c-‘0‘; c=getchar();} return x*f; } int n,m; struct item{ int p,q,w; bool operator <(const item &r)const{return q-p<r.q-r.p;} }a[N]; int f[M]; void dp(){ memset(f,0,sizeof(f)); for(int i=1;i<=n;i++) for(int j=m;j>=a[i].q;j--) f[j]=max(f[j],f[j-a[i].p]+a[i].w); } int main(int argc, const char * argv[]){ while(scanf("%d%d",&n,&m)!=EOF){ for(int i=1;i<=n;i++){a[i].p=read();a[i].q=read();a[i].w=read();} sort(a+1,a+1+n); dp(); printf("%d\n",f[m]); } return 0; }
HDU3466 Proud Merchants[背包DP 条件限制]
标签:ring lock alt cep 限制 scan 比较 rmi input
原文地址:http://www.cnblogs.com/candy99/p/6011249.html