#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
int n, k, a[501], b[501];
ld dp[1 << 20][23];
ld recurse (int mask, int c, int l) {
if (l == k) return 0;
ld &ret = dp[mask][c];
if (ret == ret) return ret;
ret = 1e18;
for (int i = 0; i < n; i++) {
if (mask & (1 << i)) continue;
ret = min(ret, 1.0 * a[i] / c + recurse(mask ^ (1 << i), c, l + 1));
}
int pos = -1, mx = 1e9;
for (int i = 0; i < n; i++) {
if (mask & (1 << i)) continue;
if (b[i] != -1 && b[i] < mx) {
mx = b[i]; pos = i;
}
}
if (pos != -1) {
ret = min(ret, 1.0 * b[pos] / c + recurse(mask ^ (1 << pos), c + 1, l + 1));
}
return ret;
}
int main () {
memset(dp, -1, sizeof(dp));
cin >> n >> k;
for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
cout << fixed << setprecision(9) << recurse(0, 1, 0) << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
143 ms |
377796 KB |
Output is correct |
2 |
Correct |
103 ms |
377960 KB |
Output is correct |
3 |
Correct |
102 ms |
377912 KB |
Output is correct |
4 |
Correct |
99 ms |
377936 KB |
Output is correct |
5 |
Runtime error |
800 ms |
766076 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
143 ms |
377796 KB |
Output is correct |
2 |
Correct |
103 ms |
377960 KB |
Output is correct |
3 |
Correct |
102 ms |
377912 KB |
Output is correct |
4 |
Correct |
99 ms |
377936 KB |
Output is correct |
5 |
Runtime error |
800 ms |
766076 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
115 ms |
377936 KB |
Output is correct |
2 |
Correct |
102 ms |
377936 KB |
Output is correct |
3 |
Correct |
106 ms |
377936 KB |
Output is correct |
4 |
Correct |
94 ms |
377948 KB |
Output is correct |
5 |
Correct |
93 ms |
377944 KB |
Output is correct |
6 |
Correct |
93 ms |
378204 KB |
Output is correct |
7 |
Correct |
94 ms |
377940 KB |
Output is correct |
8 |
Correct |
94 ms |
377940 KB |
Output is correct |
9 |
Incorrect |
101 ms |
377760 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
115 ms |
377936 KB |
Output is correct |
2 |
Correct |
102 ms |
377936 KB |
Output is correct |
3 |
Correct |
106 ms |
377936 KB |
Output is correct |
4 |
Correct |
94 ms |
377948 KB |
Output is correct |
5 |
Correct |
93 ms |
377944 KB |
Output is correct |
6 |
Correct |
93 ms |
378204 KB |
Output is correct |
7 |
Correct |
94 ms |
377940 KB |
Output is correct |
8 |
Correct |
94 ms |
377940 KB |
Output is correct |
9 |
Incorrect |
101 ms |
377760 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
115 ms |
377936 KB |
Output is correct |
2 |
Correct |
102 ms |
377936 KB |
Output is correct |
3 |
Correct |
106 ms |
377936 KB |
Output is correct |
4 |
Correct |
94 ms |
377948 KB |
Output is correct |
5 |
Correct |
93 ms |
377944 KB |
Output is correct |
6 |
Correct |
93 ms |
378204 KB |
Output is correct |
7 |
Correct |
94 ms |
377940 KB |
Output is correct |
8 |
Correct |
94 ms |
377940 KB |
Output is correct |
9 |
Incorrect |
101 ms |
377760 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
436 ms |
766036 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
143 ms |
377796 KB |
Output is correct |
2 |
Correct |
103 ms |
377960 KB |
Output is correct |
3 |
Correct |
102 ms |
377912 KB |
Output is correct |
4 |
Correct |
99 ms |
377936 KB |
Output is correct |
5 |
Runtime error |
800 ms |
766076 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |