C - Monkey and Banana HDU - 1069

思路

一种砖块可以旋转成不同的六种,将这六种都加入到队列中,然后就变成了最长上升子序列。

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=31*6;
struct Node {
	int x,y,z;
} a[N];

bool cmp(Node a,Node b)
{
	if(a.x!=b.x) return a.x<b.x;
	else return a.y<b.y;
}

int f[N];
int n,cnt,t;

int main()
{
	while(cin>>n,n)
	{
		cnt=0;
		memset(f,0,sizeof f);
		for(int i=0;i<n;i++)
		{
			int x,y,z;
			scanf("%d%d%d",&x,&y,&z);
			a[cnt++]={x,y,z};
			a[cnt++]={x,z,y};
			a[cnt++]={y,x,z};
			a[cnt++]={y,z,x};
			a[cnt++]={z,x,y};
			a[cnt++]={z,y,x};
		}
		sort(a,a+cnt,cmp);
		int ans=0;
		for(int i=0;i<cnt;i++)
		{
			f[i]=a[i].z;
			for(int j=0;j<i;j++)
			{
				if(a[i].x>a[j].x&&a[i].y>a[j].y)
				{
					f[i]=max(f[i],f[j]+a[i].z);
				}
			}
		}
		for(int i=0;i<cnt;i++) ans=max(ans,f[i]);
		printf("Case %d: maximum height = %d\n",++t,ans);
		
	}
	
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值