The main effect of the topic
There are n kinds of bricks with x,y,z and height, each of which has countless.
Bricks can be covered in different postures.
Brick A can be put on brick B in a certain posture, when and only if the length of the bottom of a is smaller than the width of the bottom of B.
How high can the tallest be built?
Ideas
For a x,y,z brick, it can be placed in 3 positions.
(top two for ground, rear one for high)
X, Y, Z
X, Z, y
Y, Z, x
Record each posture and become a brick with a 3*n fixed posture.
Then build the diagram, g[i][j] = true, which means bricks I can be covered on bricks J and vice versa.
Then it is the longest way to DAG.
Code
/**========================================== * is a solution for ACM/ICPC problem * * @source: uva-437 the Towe R of Babylon * @type: Memory Search, the longest road on the DAG * @author: Shuangde * @blog: blog.csdn.net/shuangde800 * @email: ZENGSHUANGDE@GMAIL.C Om *===========================================*/#include <iostream> #include <cstdio> #include < algorithm> #include <vector> #include <queue> #include <cmath> #include <cstring> using
namespace Std;
typedef long long Int64;
const int INF = 0X3F3F3F3F;
const int MAXN = 230;
int n;
BOOL G[MAXN][MAXN];
int F[MAXN]; struct node{int x, y, H;}
A[MAXN]; BOOL Check (int i, int j) {return a[i].x<a[j].x && a[i].y<a[j].y | |
A[i].x<a[j].y && a[i].y<a[j].x; int dfs (int u) {if (F[u]!=-1) return f[u]; F[u] = a[u].h; for (int i = 0; i < n; ++i) if (G[u][i]) {F[u] = max (f
[u], DFS (i) +a[u].h);
return F[u]; int main () {int cas = 1 while (~scanf ("%d"), &n&& N) {for (int i = 0; i < n; ++i) {scanf ("%d%d%d", &a[i].x, &a[i].y, &a[i].h); a[n+i].x=a[i].x; A[n+i].y=a[i].h;
A[N+I].H=A[I].Y; A[2*N+I].X=A[I].Y; A[2*n+i].y=a[i].h;
a[2*n+i].h=a[i].x;
} n *= 3;
memset (g, 0, sizeof (g));
for (int i = 0; i < n; ++i) for (int j = i + 1; j < n; ++j) {G[i][j] = check (i, j); G[j][i] = Check (j, i);}
int ans = 0;
Memset (F,-1, sizeof (f));
for (int i = 0; i < n; ++i) {ans = max (ans, DFS (i)), and printf ("Case%d:maximum height =%d\n", cas++, ans);
return 0; }