-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathBCLUCKY1-src.cpp
73 lines (68 loc) · 1.13 KB
/
BCLUCKY1-src.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
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
#include <iostream>
using namespace std;
long n, t[100];
long f[100][1300][1300];
long s;
long initF()
{
for (long i = 0; i <= n; i++)
for (long j = 0; j <= s; j++)
for (long k = 0; k <= s; k++) f[i][j][k] = 0;
for (long i = 1; i <= n; i++)
{
f[i][t[i]][0] = 1;
f[i][0][t[i]] = 1;
f[i][0][0] = 1;
}
}
long xuli()
{
long d = 0;
for (long i = 1; i <= n; i++)
{
d += t[i];
for (long j = 0; j <= s; j++)
for (long k = 0; k <= s; k++)
{
if (f[i - 1][j][k]) f[i][j][k] = 1;
else
if ((j >= t[i]) && (f[i - 1][j - t[i]][k])) f[i][j][k] = 1;
else
if ((k >= t[i]) && (f[i - 1][j][k - t[i]])) f[i][j][k] = 1;
}
}
}
long mx(long a, long b, long c)
{
long res = a;
if (res < b) res = b;
if (res < c) res = c;
return res;
}
long result()
{
long res = s;
for (long j = 0; j <= s; j++)
for (long k = 0; k <= s; k++)
if (f[n][j][k] == 1)
{
long d = mx(j, k, s - j - k);
if (d < res) res = d;
}
return res;
}
main()
{
while ((cin >> n) && (n != 0))
{
s = 0;
for (long i = 1; i <= n; i++)
{
cin >> t[i];
s += t[i];
}
initF();
xuli();
cout << result() << endl;
}
}