mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-23 22:48:48 +00:00
3312. [USACO2013 Nov] No Change
https://hydro.ac/d/bzoj/record/6322eb3d32ae6c3198cc9a01
This commit is contained in:
parent
67fcc9cd0a
commit
0c692c1357
69
BZOJ/3312/3312.cpp
Normal file
69
BZOJ/3312/3312.cpp
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using std::cin;
|
||||||
|
using std::cout;
|
||||||
|
const char endl = '\n';
|
||||||
|
|
||||||
|
const int N = 100005;
|
||||||
|
|
||||||
|
int k, n, w[20], s[N], f[1 << 17], ans;
|
||||||
|
bool flag;
|
||||||
|
|
||||||
|
inline int find(int x, int y) {
|
||||||
|
int l = f[x],
|
||||||
|
r = std::min(n, f[x] + w[y]);
|
||||||
|
|
||||||
|
int res = l;
|
||||||
|
while (l <= r) {
|
||||||
|
int mid = l + r >> 1;
|
||||||
|
|
||||||
|
if (s[mid] - s[f[x]] <= w[y]) {
|
||||||
|
res = mid;
|
||||||
|
l = mid + 1;
|
||||||
|
} else {
|
||||||
|
r = mid - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
cin.tie(nullptr);
|
||||||
|
|
||||||
|
cin >> k >> n;
|
||||||
|
|
||||||
|
for (int i = 0; i < k; i++) {
|
||||||
|
cin >> w[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 1, x; i <= n; i++) {
|
||||||
|
cin >> x;
|
||||||
|
|
||||||
|
s[i] = s[i - 1] + x;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 1 << k; i++) {
|
||||||
|
for (int j = 0; j < k; j++) {
|
||||||
|
if (!(i & (1 << j))) {
|
||||||
|
f[i | (1 << j)] = std::max(f[i | (1 << j)], find(i, j));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (f[i] == n) {
|
||||||
|
flag = true;
|
||||||
|
|
||||||
|
int sum = 0;
|
||||||
|
for (int j = 0; j < k; j++) {
|
||||||
|
if (!(i & (1 << j))) sum += w[j];
|
||||||
|
}
|
||||||
|
|
||||||
|
ans = std::max(ans, sum);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << (flag ? ans : -1) << endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
BZOJ/3312/data/1.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/3312/data/1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/3312/data/1.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/3312/data/1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/3312/data/10.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/3312/data/10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/3312/data/10.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/3312/data/10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/3312/data/11.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/3312/data/11.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/3312/data/11.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/3312/data/11.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/3312/data/12.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/3312/data/12.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/3312/data/12.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/3312/data/12.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/3312/data/13.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/3312/data/13.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/3312/data/13.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/3312/data/13.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/3312/data/2.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/3312/data/2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/3312/data/2.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/3312/data/2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/3312/data/3.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/3312/data/3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/3312/data/3.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/3312/data/3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/3312/data/4.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/3312/data/4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/3312/data/4.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/3312/data/4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/3312/data/5.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/3312/data/5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/3312/data/5.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/3312/data/5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/3312/data/6.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/3312/data/6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/3312/data/6.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/3312/data/6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/3312/data/7.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/3312/data/7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/3312/data/7.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/3312/data/7.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/3312/data/8.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/3312/data/8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/3312/data/8.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/3312/data/8.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/3312/data/9.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/3312/data/9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/3312/data/9.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/3312/data/9.out
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user