POJ 2241 The Tower of Babylon (UVA 437)

Source: Internet
Author: User

A variety of methods, I do with DP.

I do it as the longest descending subsequence. Asked the other person, there is a tree DP, there are differential constraints with the shortest.

There are two-dimensional knapsack problems.

The longest monotone subsequence, with a length-width high of x, Y, and Z, is enumerated as six. Then sort, and find the longest monotone subsequence.

#include <cstdio> #include <cstring> #include <string> #include <queue> #include <algorithm > #include <map> #include <stack> #include <iostream> #include <list> #include <set># include<bitset> #include <vector> #include <cmath> #define INF 0x7fffffff#define EPS 1e-8#define LL Long Long#define PI 3.141592654#define CLR (A, B) memset (A,b,sizeof (a)) #define for (I,A,B) for (int i=a;i<b;i++) #define For_ (I,A,B) for (int i=a;i>=b;i--) #define PUB push_back#define PUF push_front#define pob pop_back#define pof pop_front #define MP make_pair#define ft first#define SD second#define SF scanf#define PF printf#define sz (v) ((int) (v). Size ()) #defi NE All (v) (v). Begin (), (v). End () #define ACFUN Std::ios::sync_with_stdio (false) #define SIZE +1using namespace std;    struct point{int x, y, Z;    void init (int xx,int yy,int zz) {x=xx,y=yy,z=zz; } friend bool operator < (point A,point b) {if (a.x==b.x) {if (a.y==B.Y) return a.z>b.z;        Return a.y>b.y;    } return a.x>b.x;    }}l[size];int n;int Dp[size];int Main () {int cs=1;        while (~SF ("%d", &n), n) {int m=0;            for (i,0,n) {int x, y, Z;            SF ("%d%d%d", &x,&y,&z);            L[m++].init (x, y, z);            L[m++].init (X,z,y);            L[m++].init (Y,X,Z);            L[m++].init (Y,Z,X);            L[m++].init (Z,x,y);        L[m++].init (Z,Y,X);        } sort (l,l+m);        CLR (dp,0);                    for (I,0,m) {for (j,i+1,m) {if (L[J].X&LT;L[I].X&AMP;&AMP;L[J].Y&LT;L[I].Y)            Dp[j]=max (DP[J],DP[I]+L[I].Z);        }} int ans=0;        for (i,0,m)//pf ("%d \ n", dp[i]+l[i].z);        Ans=max (ANS,DP[I]+L[I].Z);    PF ("Case%d:maximum height =%d\n", Cs++,ans); }}


POJ 2241 The Tower of Babylon (UVA 437)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.