forked from t3nsor/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbabtwr.cpp
More file actions
39 lines (39 loc) · 697 Bytes
/
Copy pathbabtwr.cpp
File metadata and controls
39 lines (39 loc) · 697 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// 2008-07-26
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;
int n;
int x[91];
int y[91];
int h[91];
int memo[91];
int height(int k)
{
int i;
if (memo[k]!=-1)
return memo[k];
int top=0;
for (i=0; i<n; i++)
if (x[i]<x[k]&&y[i]<y[k]||x[i]<y[k]&&y[i]<x[k])
top=max(top,height(i));
return memo[k]=h[k]+top;
}
int main()
{
int i;
for(;;)
{
scanf("%d",&n);
if (!n) return 0;
for (i=0; i<n; i++)
{
scanf("%d %d %d",x+i,y+i,h+i);
x[i+n]=y[i]; y[i+n]=h[i]; h[i+n]=x[i];
x[i+2*n]=h[i]; y[i+2*n]=x[i]; h[i+2*n]=y[i];
}
x[3*n]=2000000000; y[3*n]=2000000000; h[3*n]=0;
n=3*n+1;
memset(memo,-1,sizeof(memo));
printf("%d\n",height(n-1));
}
};