QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#72984 | #4377. Backpack | LiCooer | AC ✓ | 385ms | 9688kb | C++17 | 2.3kb | 2023-01-21 13:07:38 | 2023-01-21 13:07:41 |
Judging History
answer
//By TOP
#include <iostream>
#include <algorithm>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <list>
#include <unordered_set>
#include <cmath>
#include <bits/stdc++.h>
#include <deque>
#include <vector>
#include <utility>
using namespace std;
#define int long long
typedef pair<int,int> PII;
#define OO 0x3f3f3f3f
#define rd read()
#define mem(a,b) memset(a,b,sizeof a)
#define ios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define v1 priority_queue<int,vector<int>,greater<int> > v
#define v2 priority_queue<int,vector<int>,less<int> > v
#define debug(a) cout << a << "\n"
const int N = 2000010;
int a[N];
int n;
int tr[N];
/*void build(int u , int l , int r)
{
tr[u] = {l , r};
if(l == r)
{
return ;
}
int mid = l + r >> 1;
build(u << 1 , l , mid);
build(u << 1 | 1 , mid + 1 ,r);
}*/
/*int query(int u , int l , int r)
{
if(tr[u].l >= l && tr[u].r <= r)
{
return tr[u].v;
}
int mid = tr[u].l + tr[u].r >> 1;
int v = 0;
if(l <= mid)
{
v.query(u << 1 , l , r);
}
if(r > mid)
{
v.query(u << 1 | 1 , l , r);
}
return v;
}*/
int lowbit(int x)
{
return x & -x;
}
void add(int x,int c)
{
for(int i = x ; i <= n ; i += lowbit(i) )
{
tr[i] += c;
}
}
int query(int x)
{
int res = 0;
for(int i = x ; i ; i -= lowbit(i))
{
res += tr[i];
}
return res;
}
inline int read()
{
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - 48;
ch = getchar();
}
return x * f;
}
bitset<1050> dp[1050] , res[1050];
int v[N];
int w[N];
void solve()
{
int n , m;
cin >> n >> m;
for(int i = 0 ; i <= 1024 ; i ++ )
{
dp[i].reset();
}
for(int i = 1 ; i <= n ; i ++ )
{
cin >> v[i] >> w[i];
}
dp[0][0] = 1;
for(int i = 1 ; i <= n ; i ++ )
{
for(int j = 1023 ; j >= 0 ; j -- )
{
res[j] = dp[j];
}
for(int j = 1023 ; j >= 0 ; j -- )
{
dp[j] |= res[j ^ w[i]] << v[i];
}
}
int ans = -1;
for(int i = 0 ; i < 1024 ; i ++ )
{
if(dp[i][m])
{
ans = i;
}
}
cout << ans << "\n";
}
signed main()
{
ios;
int t = 1;
cin >> t;
while(t -- )
{
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 385ms
memory: 9688kb
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