-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbestCoalitions_UVA11658.cpp
67 lines (54 loc) · 1.4 KB
/
bestCoalitions_UVA11658.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
#include <bits/stdc++.h>
using namespace std;
ifstream fin("bestCoalitions_UVA11658.in");
ofstream fout("bestCoalitions_UVA11658.out");
const int N = 10000;
int main()
{
fout << fixed << setprecision(2);
while (true)
{
int n = 0, x = 0; fin >> n >> x;
if (n + x == 0) break;
vector<int> a(n + 1, 0);
for (int i = 1; i <= n; ++i)
{
double temp; fin >> temp;
a[i] = (int)(temp * 100 + 0.5);
}
if (a[x] > 5000)
{
fout << "100.00\n";
continue;
}
int _max = N - a[x];
vector<int> dp(N + 1, 0); dp[0] = 1;
for (int i = 1; i <= n; ++i)
{
if (i == x) continue;
for (int j = _max - a[i]; j >= 0; --j)
{
if (dp[j] == 1)
{
dp[j + a[i]] = 1;
}
}
}
// for (int i = 0; i <= N; ++i)
// {
// if (dp[i] == 1)
// {
// fout << i << '\n';
// }
// }
int other = 5001 - a[x];
while (dp[other] == 0)
{
++other;
}
double now_d = a[x], other_d = other;
double ans = 100.0 * now_d / (now_d + other_d);
fout << ans << '\n';
}
return 0;
}