Uvaoj 437 The Tower of Babylon simple DP

Source: Internet
Author: User
Tags printf sort
Uvaoj 437 The tower of Babylon simple DP with a given number of types of bricks to build a tower, a brick (x, Y, z) three dimensions to represent, you can rotate them arbitrarily to make one face the bottom surface, the other surface becomes high, the process of building the tower, The top two dimensions of the face of the brick must be smaller than the two dimensions of the bottom face, and the number of bricks for each type is infinitely greater. Because it can be rotated arbitrarily, each brick can be rotated to get six kinds of the bottom of the brick (temporarily ignore the rotation to get the same), so, for each type of brick by rotation to get six different bricks, and then DP on the line, Dp[i] is labeled I as the bottom of the brick to the height of the tower, Note that the type of bricks must be sorted from small to large (x, Y, z) before DP. The code is as follows:
/************************************************************************* > File name:437.cpp > Author:gwq &G T mail:gwq5210@qq.com > Created time:2014 December 19 Friday 20:10 17 seconds **************************************************** /#include <cmath> #include <ctime> #include <cctype> #include <climits> # Include <cstdio> #include <cstdlib> #include <cstring> #include <map> #include <set> #incl Ude <queue> #include <stack> #include <string> #include <vector> #include <sstream> # Include <iostream> #include <algorithm> #define INF (INT_MAX/10) #define CLR (arr, Val) memset (arr, Val, siz
EOF (ARR)) #define PB push_back #define SZ (a) ((int) (a). Size ()) using namespace Std;
typedef set<int> SI;
typedef vector<int> VI;
typedef map<int, Int> Mii;

typedef long Long LL;

Const double ESP = 1e-5;

	#define N + struct Node {int x, y, Z; void InpuT (void) {scanf ("%d%d%d", &x, &y, &z);
		int a[3] = {x, y, z};
		Sort (A, a + 3);
		x = a[0];
		y = a[1];
	z = a[2];
	} void output (void) {printf ("%d%d%d\n", X, Y, z);

}}node[n];
int dp[n];

Node Tmp[n];
		BOOL CMP (node u, node v) {if (u.x = = v.x) {if (u.y = = v.y) {return u.z < v.z;
		} else {return u.y < v.y;
	}} else {return u.x < v.x;
	}} int main (int argc, char *argv[]) {int n;
	int c = 0;
		while (scanf ("%d", &n)! = EOF) {if (n = = 0) {break;
		} for (int i = 0; i < n; ++i) {tmp[i].input ();
		} int len = 0;
			for (int i = 0; i < n; ++i) {node[len++] = Tmp[i];
			node[len].x = TMP[I].Y;
			Node[len].y = tmp[i].z;
			Node[len].z = tmp[i].x;
			len++;
			node[len].x = tmp[i].x;
			Node[len].y = tmp[i].z;
			Node[len].z = TMP[I].Y;
			len++;
			node[len].x = tmp[i].z;
			Node[len].y = tmp[i].x;
			Node[len].z = TMP[I].Y;
			len++;
			node[len].x = tmp[i].z;
			Node[len].y = TMP[I].Y; NODE[LEN].Z = TMp[i].x;
			len++;
			node[len].x = TMP[I].Y;
			Node[len].y = tmp[i].x;
			Node[len].z = tmp[i].z;
		len++;
		}//for (int i = 0; i < len; ++i) {//node[i].output ();
		}//printf ("-------------\ n");
		Sort (node, node + len, CMP);
		for (int i = 0; i < len; ++i) {//node[i].output ();
		}//printf ("-------------\ n");
		CLR (DP, 0);
		Dp[0] = node[0].z;
			for (int i = 1; i < Len; ++i) {dp[i] = node[i].z; for (int j = 0; J < i; ++j) {if (node[j].x < node[i].x && Node[j].y < node[i].y && Dp[i] &lt ;
				DP[J] + node[i].z) {Dp[i] = Dp[j] + node[i].z;
		}}} int res = 0;
		for (int i = 0; i < len; ++i) {res = max (res, dp[i]);
	} printf ("Case%d:maximum height =%d\n", ++c, RES);
} return 0; }


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.