HDU 1069 Monkey and Banana (dp, 最长上升子序列)
2017-10-04 16:49
375 查看
题目链接: HDU 1069
题意: 给定n个长方体,每个长方体均有长、宽、高. 将这些长方体(可重复使用)叠起来,满足上面的长方体的长宽>下面的长方体的长宽( 长>长,宽>宽,为严格> )的条件下. 问叠出来的高度最高为多少?
解法: 一个长方体可分为6种类型的长方体( 以不同的边为底边 ), 按照长排序后,进行最长上升子序列求解,即可得到答案.
题意: 给定n个长方体,每个长方体均有长、宽、高. 将这些长方体(可重复使用)叠起来,满足上面的长方体的长宽>下面的长方体的长宽( 长>长,宽>宽,为严格> )的条件下. 问叠出来的高度最高为多少?
解法: 一个长方体可分为6种类型的长方体( 以不同的边为底边 ), 按照长排序后,进行最长上升子序列求解,即可得到答案.
#include<bits/stdc++.h> using namespace std; #define mp make_pair #define pb push_back #define fir first #define sec second #define repp(i, a, b) for(int i=(b); i>=(a); --i) #define rep(i,a,b) for (int i=(a); i<=(b); ++i) #define de(x) cout<< #x << " => " << (x) << endl #define ms(a, b) memset(a, b, sizeof(a)) typedef long long ll; typedef pair<int,int> pii; typedef vector<int> vi; const int inf = 0x3f3f3f3f; const double PI=acos(-1); const double eps=1e-9; inline void file_put() { freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); } const int maxn = 300; int n; struct node{ int w, l , h, area; }p[maxn]; int len = 0; void add(int x, int y, int z){ p[len].l = x , p[len].w = y , p[len++].h = z; p[len].l = y , p[len].w = x, p[len++].h = z; p[len].l = x , p[len].w = z, p[len++].h = y; p[len].l = z , p[len].w = x, p[len++].h = y; p[len].l = y , p[len].w = z, p[len++].h = x; p[len].l = z , p[len].w = y, p[len++].h = x; return ; } bool cmp(node a, node b){ if(a.l != b.l) return a.l < b.l; else if(a.w != b.w)return a.w < b.w; } int dp[maxn]; int main() { // file_put(); int cas=0; while(~scanf("%d", &n), n){ cout << "Case "<<++cas<<": maximum height = "; len = 0; int x, y, z; ms(dp, 0); rep(i, 1, n){ scanf("%d %d %d", &x, &y, &z) ; add(x, y, z); } sort(p, p+len, cmp); rep(i, 0, len-1){ dp[i] = p[i].h; rep(j, 0, i-1){ if(p[i].l>p[j].l && p[i].w >p[j].w){ if(dp[i] < dp[j] + p[i].h){ dp[i] = dp[j] + p[i].h; } } } } int ans = 0; rep(i, 0, len-1){ ans = max(dp[i], ans); } cout << ans<<endl; } return 0; }
相关文章推荐
- HDU 1069 Monkey and Banana(dp最长上升子序列)
- hdu 1069 Monkey and Banana(dp 最长上升子序列)
- HDU Monkey and Banana 1069 dp 动态规划 最长递增子序列
- hdu 1069 Monkey and Banana 最长上升子序列。
- HDU 1069 Monkey and Banana(LIS最长上升子序列)
- HDU 1069 Monkey and Banana (最长上升子序列)
- hdu 1069 Monkey and Banana(类似最长上升子序列,dp)
- hdu 1069 Monkey and Banana 再来一波DP啦~~LIS的变形,会最大上升子序列就可以A啦~
- hdu 1069 Monkey and Banana (最长上升子序列)
- HDU 1069 Monkey and Banana 最长上升子序列模板
- HDU - 1096 - Monkey and Banana(最长上升子序列)
- 三维最长上升子序列问题——HDU 1069 Monkey and Banana
- hdu 1069 Monkey and Banana--最长递增子序列
- hdu 1069 monkey and banana(最长下降子序列)
- HDU 1069 Monkey and Banana(最长递减子序列)
- (DP,最长上升子序列变形)Monkey and Banana--HDOJ
- (hdu step 3.2.6)Monkey and Banana(在第一关键字有序的情况下,根据第二关键字求最长上升子序列的高度之和)
- HDU 1069 Monkey and Banana(DP 长方体堆放问题)
- HDU 1069 Monkey and Banana DP LIS变形题
- HDU - 1069 Monkey and Banana(dp)