/*
基础dp
C - Monkey and Banana
时间: 2017/02/20
题意:叠放立方体,使其叠的高度最大。在按底的长宽排序后,进行求最大子序列和
题解:
1. 在按底的长宽排序后,进行求最大子序列和
2. 类似嵌套问题,记忆化搜索
*/
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
#define N 210
#define INF 0x3f3f3f3f
struct code
{
int x,y,z;
}f[N];
int mp[N][N],dp[N];
int n;
int dfs(int i)
{
int &ans = dp[i];
if(ans > 0) return ans;
ans = f[i].z;
for(int j = 0; j < 3*n; j++)
{
if(mp[i][j])
ans = max(ans, dfs(j)+f[i].z);
}
return ans;
}
int main()
{
int k = 0;
while(~scanf("%d",&n)&&n)
{
k++;
int n1 = n;
int i = 0;
while(n1--)
{
int a[3];
scanf("%d%d%d",&a[0],&a[1],&a[2]);
sort(a,a+3);
f[i].y = f[i+1].z = f[i+2].x = a[1];
f[i].x = f[i+1].x = f[i+2].z = a[2];
f[i].z = f[i+1].y = f[i+2].y = a[0];
i += 3;
}
memset(mp,0,sizeof(mp));
memset(dp,0,sizeof(dp));
for(int i = 0; i < 3*n; i++)
{
for(int j = 0; j < 3*n; j++)
{
if(f[i].x < f[j].x && f[i].y < f[j].y)
mp[i][j] = 1;
}
}
int maxn = 0;
for(int i = 0; i < 3*n; i++)
{
maxn = max(maxn,dfs(i));
}
printf("Case %d: maximum height = %d\n",k,maxn);
}
return 0;
}
【dp】HDU - 1069 Monkey and Banana
最新推荐文章于 2020-03-20 22:06:05 发布