-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtower.cpp
More file actions
97 lines (96 loc) · 1.75 KB
/
Copy pathtower.cpp
File metadata and controls
97 lines (96 loc) · 1.75 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<iostream>
using namespace std;
struct brick {
int x;
int y;
int z;
int h;
};
brick *zt = (brick*)malloc(sizeof(brick) * 200);
int lx = 0, ly = 0, sz = 0, maxi = 0, place = 0;
void dfs(int z) {
sz += zt[z].z;
if (sz > maxi)maxi = sz;
for (int i=0; i < place; i++) {
if (zt[i].x < zt[z].x && zt[i].y < zt[z].y) {
dfs(i);
}
}
sz -= zt[z].z;
}
int main() {
int number=0;
int x = 0, y = 0, z = 0;
while (1) {
sz = 0;
maxi = 0;
scanf("%d", &number);
if (number == 0)return 0;
place = 0;
for (int i = 0; i < number; i++) {
scanf("%d %d %d", &x, &y, &z);
{
if (y > x) {//let x>=y
zt[place].x = y;
zt[place].y = x;
zt[place].z = z;
}
else {
zt[place].x = x;
zt[place].y = y;
zt[place].z = z;
}
zt[place].h = z;
place++;
if (x > z) {
zt[place].x = x;
zt[place].y = z;
zt[place].z = y;
}
else {
zt[place].x = z;
zt[place].y = x;
zt[place].z = y;
}
zt[place].h = y;
place++;
if (y > z) {
zt[place].x = y;
zt[place].y = z;
zt[place].z = x;
}
else {
zt[place].x = z;
zt[place].y = y;
zt[place].z = x;
}
zt[place].h = x;
place++;//may need revise
}
}
/*for (int i = 0; i < place; i++) {
dfs(i);
}*/
int test = 1;
while (test == 1) {
test = 0;
for (int a = 0; a < place; a++) {
for (int b = 0; b < place; b++) {
if (zt[a].z + zt[b].h <= zt[a].h)continue;
if (zt[a].x > zt[b].x && zt[a].y > zt[b].y) {//b can ·ÅÔÚaÉÏ
zt[a].h= zt[a].z + zt[b].h;
test=1;
}
}
}
}
for (int i = 0; i < place; i++) {
if (maxi < zt[i].h)maxi = zt[i].h;
}
printf("%d\n", maxi);
}
free(zt);
}