这里要注意max赋初值的时候要赋值为0,不能为-1,因为答案有可能为0
#include <iostream> #include <cmath> #include <cstring> #include <cstdio> #include <cstdlib> #include <algorithm> using namespace std; int type; int f[44444],usr[44444]; struct Block { int h,a,c; }block[555]; bool cmp(Block a,Block b) { return a.a<b.a; } int main() { scanf("%d",&type); for(int i=1;i<=type;i++) { scanf("%d%d%d",&block[i].h,&block[i].a,&block[i].c); } sort(block+1,block+1+type,cmp); int maxn=0; f[0]=1; for(int t=1;t<=type;t++) { memset(usr,0,sizeof(usr)); for(int h=block[t].h;h<=block[t].a;h++) { if(!f[h] && f[h-block[t].h] && usr[h-block[t].h]+1<=block[t].c) { usr[h]=usr[h-block[t].h]+1; f[h]=1; maxn=max(h,maxn); } } } printf("%d\n",maxn); return 0; }
POJ2392 SpaceElevator [DP],布布扣,bubuko.com
原文地址:http://blog.csdn.net/u011775691/article/details/36768881