Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 8110 | Accepted: 3843 |
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; struct Class{ int h,maxh,c; }a[405]; int cmp(Class x,Class y) { return x.maxh<y.maxh; } int main() { int n,ans,i,j,dp[40005],sum[40005]; while(cin>>n) { for( i=0;i<n;i++) cin>>a[i].h>>a[i].maxh>>a[i].c; sort(a,a+n,cmp); memset(dp,0,sizeof(dp)); dp[0]=1; int ans=0; for(i=0;i<n;i++) { memset(sum,0,sizeof(sum)); for(j=a[i].h;j<=a[i].maxh;j++) { if(!dp[j]&&dp[j-a[i].h]&&sum[j-a[i].h]<a[i].c) { dp[j]=1; sum[j]=sum[j-a[i].h]+1;//统计石块放置的个数 if(ans<j) ans=j; } } } cout<<ans<<endl; } return 0; }
poj 2392 Space Elevator (多重背包)
原文地址:http://blog.csdn.net/fanerxiaoqinnian/article/details/38020381