Analysis: Variant of the oldest sequence; the other box can have three kinds of methods, three kinds of methods exist in the same array, because each box can have an infinite number of.
#include <iostream> #include <algorithm>using namespace std;struct box{int x, Y, Z;} box[100];int dp[100]; BOOL CMP (BOX A,box b) {if (a.x>b.x) return True;else if (a.x==b.x && a.y>b.y) return true;else return false;} int main () {int n,i,k,j,max,t;int tmp[4]; T=0;while (cin>>n && N) {k=0;for (i=0;i<n;i++) {Cin>>tmp[0]>>tmp[1]>>tmp[2];sort ( TMP,TMP+3); Three kinds of box[k].x=tmp[2];box[k].y=tmp[1];box[k++].z=tmp[0];box[k].x=tmp[2];box[k].y=tmp[0];box[k++].z=tmp[1 per box] ; box[k].x=tmp[1];box[k].y=tmp[0];box[k++].z=tmp[2];} Sort (box,box+k,cmp); memset (Dp,0,sizeof (DP)); Max=0;for (i=0;i<k;i++) {dp[i]=box[i].z;max=max>dp[i]?max:dp[i ];for (j=0;j<i;j++) if (box[j].x>box[i].x && box[j].y>box[i].y) dp[i]=dp[i]>dp[j]+box[i].z?dp[i] :d p[j]+box[i].z;max=max>dp[i]?max:dp[i];} cout<< "Case" <<++T<< ": Maximum height =" <<MAX<<ENDL;} return 0;}
HDU ACM 1069 Monkey and banana-> dynamic planning