UVa 437. The Tower of Babylon
2015-02-07 21:54
295 查看
题意为输入若干种立方体(每种若干个),然后将立方体堆成一个塔,要求接触的两个面下底面的长宽分别严格大于上底面,求塔的最大高度。
所以长方体有六种摆放方法,长宽互换也算,因为要求下底面的长宽严格大于上底面.之后按照下底面面积排序,根据两个面下底面的长宽分别严格大于上底面的条件寻找一个最长上升子序列就可以了。
所以长方体有六种摆放方法,长宽互换也算,因为要求下底面的长宽严格大于上底面.之后按照下底面面积排序,根据两个面下底面的长宽分别严格大于上底面的条件寻找一个最长上升子序列就可以了。
/*********************************************** * Author: fisty * Created Time: 2015/2/2 16:32:40 * File Name : uva437.cpp *********************************************** */ #include <iostream> #include <cstring> #include <deque> #include <cmath> #include <queue> #include <stack> #include <list> #include <map> #include <set> #include <string> #include <vector> #include <cstdio> #include <bitset> #include <algorithm> using namespace std; #define Debug(x) cout << #x << " " << x <<endl #define Memset(x, a) memset(x, a, sizeof(x)) #define MAX_N 1000 const int INF = 0x3f3f3f3f; typedef long long LL; typedef pair<pair<int, int>, int> P; int n; P Tower[MAX_N]; bool cmp(P a, P b){ return a.first.first * a.first.second < b.first.first * b.first.second; } int main() { //freopen("in.cpp", "r", stdin); cin.tie(0); ios::sync_with_stdio(false); int kcase = 1; while(cin >> n){ if(!n) break; int cnt = 0; for(int i = 0;i < n; i++){ int x, y, z; cin >> x >> y >> z; Tower[cnt].first.first = x; Tower[cnt].first.second = y;Tower[cnt++].second = z; Tower[cnt].first.first = y; Tower[cnt].first.second = z;Tower[cnt++].second = x; Tower[cnt].first.first = z; Tower[cnt].first.second = x;Tower[cnt++].second = y; Tower[cnt].first.first = y; Tower[cnt].first.second = x;Tower[cnt++].second = z; Tower[cnt].first.first = z; Tower[cnt].first.second = y;Tower[cnt++].second = x; Tower[cnt].first.first = x; Tower[cnt].first.second = z;Tower[cnt++].second = y; } sort(Tower, Tower + cnt, cmp); int dp[MAX_N]; int ans = 0; Memset(dp, 0); for(int i = 0;i < cnt; i++){ dp[i] = Tower[i].second; for(int j = 0;j < i; j++){ if(Tower[i].first.first > Tower[j].first.first && Tower[i].first.second > Tower[j].first.second){ dp[i] = max(dp[i], dp[j] + Tower[i].second); } } if(dp[i] > ans){ ans = dp[i]; } } cout << "Case " << kcase++ <<": maximum height = " << ans << endl; } return 0; }
相关文章推荐
- uva 437 The Tower of Babylon
- UVa 437 - The Tower of Babylon
- UVA 437 The Tower of Babylon
- uva 437 The Tower of Babylon(DAG的DP)
- uva 437 - The Tower of Babylon(DP)
- UVA 437 - The Tower of Babylon 动规
- uva437 - The Tower of Babylon(动规,记忆化搜索)
- uva_437_The Tower of Babylon
- UVa 437 - The Tower of Babylon
- UVa 437 The Tower of Babylon (DP&DAG)
- uva 437 - The Tower of Babylon
- UVA 437 - The Tower of Babylon
- UVa 437 - The Tower of Babylon
- UVA - 437 The Tower of Babylon
- UVa 437 - The Tower of Babylon LIS
- UVA 437 The Tower of Babylon
- UVA 437 - The Tower of Babylon
- UVA 437 The Tower of Babylon (dp + DAG最长序列)
- UVa 437 - The Tower of Babylon
- UVa 437 The Tower of Babylon