POJ 2241 The Tower of Babylon(UVA 437),poj2241

來源:互聯網
上載者:User

POJ 2241 The Tower of Babylon(UVA 437),poj2241

多種方法,我用DP做的。

我當成的 最長下降子序列做的。 問了下其他人,有樹形DP的,有差分約束用最短路的。

還有當作 二維的背包問題的。

最長單調子序列,長寬高 x,y,z 分別枚舉成六個。然後排序,找最長單調子序列即可。

#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())#define all(v) (v).begin(),(v).end()#define acfun std::ios::sync_with_stdio(false)#define SIZE 200 +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<l[i].x&&l[j].y<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);    }}


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.