QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#41324 | #4377. Backpack | 01shijian# | AC ✓ | 517ms | 4596kb | C++17 | 1.3kb | 2022-07-29 16:07:13 | 2022-07-29 16:07:14 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef LOCAL
#include <debugger>
clock_t start = clock();
#else
#define debug(...) 42
#endif
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
constexpr int N = 1 << 11;
bitset<N> f[N];
bitset<N> g[N];
// bitset<N> now[N];
int main() {
// freopen("1.out", "w", stdout);
cin.tie(nullptr)->sync_with_stdio(false);
auto solve = [&] () {
int n, m; cin >> n >> m;
for(int i = 0; i < N; i ++ ) f[i].reset(), g[i].reset();
//f[j]表示价值为j的时候的所有体积和
f[0][0] = 1, g[0][0] = 1;
for(int i = 0; i < n; i ++ ) {
int v, w; cin >> v >> w;
// for(int j = 0; j < N; j ++ ) g[j] = f[j];
for(int j = 0; j < (1 << 10); j ++ ) {
g[j ^ w] |= (f[j] << v);
}
for(int j = 0; j < N; j ++ ) {
f[j] = g[j];
}
}
for(int i = 1023; i >= 0; i -- ) if(f[i][m]) {
cout << i << "\n";
return ;
}
cout << "-1\n";
};
int T; cin >> T;
while (T --) {
solve();
}
#ifdef LOCAL
clock_t ends = clock();
cout << "\n\nRunning Time : " << (double) (ends - start) / CLOCKS_PER_SEC * 1000 << "ms" << endl;
#endif
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 517ms
memory: 4596kb
input:
10 1023 401 179 441 416 951 420 984 1013 984 683 914 407 984 96 523 374 190 974 190 739 441 518 523 194 984 415 523 149 441 235 984 809 441 469 441 436 919 437 919 7 919 818 984 962 190 37 919 371 523 417 914 431 914 213 190 340 441 254 919 223 951 123 190 339 951 322 441 218 441 284 919 533 190 187...
output:
1021 1011 -1 1023 1023 1023 1023 1023 1023 513
result:
ok 10 lines