很经典的一个转化题目,我感觉这种转化成求图的最长路径的操作是真的骚,
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<deque>
#include<map>
#include<stdlib.h>
#include<set>
#include<iomanip>
#include<stack>
#define ll long long
#define ms(a,b) memset(a,b,sizeof(a))
#define lowbit(x) x & -x
#define fi first
#define ull unsigned long long
#define se second
#define endl "\n"
#define bug cout<<"----acac----"<<endl
#define IOS ios::sync_with_stdio(false), cin.tie(0),cout.tie(0)
using namespace std;
const int maxn =3e3 + 5;
const int maxm = 1.5e5+50;
const double eps = 1e-7;
const double inf = 0x3f3f3f3f;
const double lnf = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9+7;
const int p=1e7+233;
const double pi=3.141592653589;
struct node
{
int x,y,z;
}a[105];
bool operator<(const node &A,const node &B)//重载<号
{
return (A.x<B.x&&A.y<B.y)||(A.x<B.y&&A.y<B.x);
}
vector<int>ve[105];
int ans[105];
void dfs(int x)
{
int ma=0;
if(ans[x]!=-1)return ;
for(int i=0;i<ve[x].size();i++)
{
dfs(ve[x][i]);
ma=max(ma,ans[ve[x][i]]);
}
ans[x]=ma+a[x].z;
}
int main()
{
int n;
int cas=1;
while(~scanf("%d",&n))
{
if(n==0)break;
for(int i=0;i<=n*3;i++)
{
ve[i].clear();
}
for(int i=0;i<n;i++)
{
int x,y,z;
scanf("%d%d%d",&x,&y,&z);//分成三种情况,每种情况z都不同
a[i*3].x=x;
a[i*3].y=y;
a[i*3].z=z;
a[i*3+1].x=x;
a[i*3+1].y=z;
a[i*3+1].z=y;
a[i*3+2].x=z;
a[i*3+2].y=y;
a[i*3+2].z=x;
}
for(int i=0;i<3*n;i++)
{
for(int j=0;j<3*n;j++)
{
if(a[i]<a[j])//重载小于号的用处
{
ve[i].push_back(j);
}
}
}
ms(ans,-1);
int ma=0;
for(int i=0;i<3*n;i++)//枚举每个点为起点的最长路径
{
dfs(i);
ma=max(ma,ans[i]);
}
printf("Case %d: maximum height = %d\n",cas++,ma);
}
return 0;
}