Uva 437-the Tower of Babylon (DP)

Source: Internet
Author: User

Topic Link: Click to open the link

The longest road on a DAG,

Test instructions: Gives a box of N, (each infinite), the maximum height required to be able to stack. The edge is large and even small.

#include <algorithm> #include <iostream> #include <cstring> #include <cstdlib> #include < string> #include <cctype> #include <vector> #include <cstdio> #include <cmath> #include < queue> #include <stack> #include <map> #include <set> #define MAXN 10000002#define _ll __int64# Define ll long long#define INF 0x3f3f3f3f#define Mod 10000007#define pp pair<int,int> #define ull unsigned long Longu    Sing namespace Std;int n,m,dp[110],x[110],y[110],z[110];bool ma[110][110];void input () {m=n*3;        for (int i=1;i<=m-2;i+=3) {scanf ("%d%d%d", x+i,y+i,z+i);        X[i+1]=y[i];y[i+1]=z[i];z[i+1]=x[i];    X[I+2]=Y[I+1];Y[I+2]=Z[I+1];Z[I+2]=X[I+1];    }}void build () {memset (ma,0,sizeof (MA));    Memset (Dp,0,sizeof (DP)); for (int i=1;i<=m;i++) for (int j=i+1;j<=m;j++) {if ((x[i]>x[j]&&y[i]>y[j)) | |            (X[i]>y[j]&&y[i]>x[j]))        Ma[i][j]=1; else if ((X[J]&GT;X[I]&AMP;&AMp;y[j]>y[i]) | |            (X[j]>y[i]&&y[j]>x[i]))    Ma[j][i]=1;    }}int dfs (int x) {int& ans=dp[x];    if (ans) return ans;    ANS=Z[X];    for (int i=1;i<=m;i++) {if (Ma[x][i]) Ans=max (Ans,dfs (i) +z[x]); } return ans;        int main () {int cas=1;while (scanf ("%d", &n) &&n) {input ();        Build ();        int ans=-inf;        for (int i=1;i<=m;i++) Ans=max (Ans,dfs (i)); printf ("Case%d:maximum height =%d\n", Cas++,ans);} return 0;}


Uva 437-the Tower of Babylon (DP)

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.