mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-08 16:18:46 +00:00
parent
18d52819b2
commit
90b2034295
69
Luogu/P3092/P3092.cpp
Normal file
69
Luogu/P3092/P3092.cpp
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using std::cin;
|
||||||
|
using std::cout;
|
||||||
|
const char endl = '\n';
|
||||||
|
|
||||||
|
const int N = 100005;
|
||||||
|
|
||||||
|
int n, k, w[16], sum[N], f[0xffff + 5], ans;
|
||||||
|
bool flag;
|
||||||
|
|
||||||
|
int find(int x, int y) {
|
||||||
|
int l = f[x],
|
||||||
|
r = std::min(n, f[x] + w[y]); // 优化:每个物品的最小价值为 1
|
||||||
|
int res = l;
|
||||||
|
|
||||||
|
while (l <= r) {
|
||||||
|
int mid = l + r >> 1;
|
||||||
|
if (sum[mid] - sum[f[x]] <= w[y]) {
|
||||||
|
res = mid;
|
||||||
|
l = mid + 1;
|
||||||
|
} else {
|
||||||
|
r = mid - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
|
||||||
|
cin >> k >> n;
|
||||||
|
|
||||||
|
for (int i = 0; i < k; i++) {
|
||||||
|
cin >> w[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 1, x; i <= n; i++) {
|
||||||
|
cin >> x;
|
||||||
|
sum[i] = sum[i - 1] + x;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 1 << k; i++) {
|
||||||
|
for (int j = 0; j < k; j++) {
|
||||||
|
if ((i >> j) & 1) continue;
|
||||||
|
f[i | (1 << j)] = std::max(f[i | (1 << j)], find(i, j));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (f[i] == n) { // 全部购买完
|
||||||
|
flag = true;
|
||||||
|
int cnt = 0;
|
||||||
|
|
||||||
|
for (int j = 0; j < k; j++) {
|
||||||
|
if (!((i >> j) & 1)) cnt += w[j];
|
||||||
|
}
|
||||||
|
|
||||||
|
ans = std::max(ans, cnt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flag) {
|
||||||
|
cout << ans << endl;
|
||||||
|
} else {
|
||||||
|
cout << -1 << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
Luogu/P3092/data/1.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P3092/data/1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3092/data/1.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P3092/data/1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3092/data/10.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P3092/data/10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3092/data/10.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P3092/data/10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3092/data/11.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P3092/data/11.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3092/data/11.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P3092/data/11.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3092/data/12.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P3092/data/12.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3092/data/12.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P3092/data/12.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3092/data/13.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P3092/data/13.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3092/data/13.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P3092/data/13.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3092/data/2.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P3092/data/2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3092/data/2.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P3092/data/2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3092/data/3.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P3092/data/3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3092/data/3.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P3092/data/3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3092/data/4.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P3092/data/4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3092/data/4.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P3092/data/4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3092/data/5.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P3092/data/5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3092/data/5.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P3092/data/5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3092/data/6.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P3092/data/6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3092/data/6.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P3092/data/6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3092/data/7.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P3092/data/7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3092/data/7.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P3092/data/7.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3092/data/8.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P3092/data/8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3092/data/8.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P3092/data/8.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3092/data/9.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P3092/data/9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3092/data/9.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P3092/data/9.out
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user