-
Notifications
You must be signed in to change notification settings - Fork 103
/
BABTWR.cpp
42 lines (37 loc) · 834 Bytes
/
BABTWR.cpp
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
40
41
42
/*
USER: zobayer
TASK: BABTWR
ALGO: dp
*/
#include <stdio.h>
#include <string.h>
#define MAX 111
struct boxtype {int x, y, z;} box[MAX];
int dp[MAX], total;
int solve(int i) {
if(dp[i]) return dp[i];
int h, maxh, b;
for(maxh=b=0; b<total; b++)
if(box[b].x < box[i].x && box[b].y < box[i].y)
if((h=solve(b))>maxh)
maxh = h;
return dp[i] = maxh + box[i].z;
}
int main() {
int n, i, k, x, y, z, h, maxh;
while(scanf("%d", &n)==1 && n) {
memset(dp, 0, sizeof(dp));
for(i=k=0; i<n; i++) {
scanf("%d%d%d", &x, &y, &z);
box[k++] = (x<y)? (boxtype){x,y,z}:(boxtype){y,x,z};
box[k++] = (x<z)? (boxtype){x,z,y}:(boxtype){z,x,y};
box[k++] = (y<z)? (boxtype){y,z,x}:(boxtype){z,y,x};
}
total = k;
for(i=maxh=0; i<total; i++)
if((h=solve(i))>maxh)
maxh = h;
printf("%d\n", maxh);
}
return 0;
}