当前位置:网站首页>Hangdian multi School Game 1 question 3 backpack (XOR dp+bitset)
Hangdian multi School Game 1 question 3 backpack (XOR dp+bitset)
2022-07-24 18:48:00 【Dusk of fools】
Alice has n project , Each project has a volume v Me and value w I .
Can I go from n Select multiple items from the items , So that the backpack is completely filled ( That is, the total volume is equal to the backpack capacity )? If so , When the back package is full , What is the maximum XOR sum of the value of items in the backpack ?
The first line of each test case contains 2 It's an integer n,m(1≤n,m<2^10)— Quantity of articles , Backpack Capacity .
next n That's ok , Each row contains 2 It's an integer v I ,w I (1≤v I ,w I <2^10)— The number and value of the project .
Output
#include <iostream>
#include <algorithm>
#include <cstring>
#include <bitset>
using namespace std;
const int N=1050;
int n,m;
bitset<N> f[N],g[N];
void init(){
for(int i=0;i<=1024;i++){
f[i].reset();
}
f[0][0]=1;
}
int main(){
int t;
cin>>t;
while(t--){
cin>>n>>m;
init();
for(int i=0;i<n;i++){
int v,m1;
cin>>v>>m1;
for(int j=0;j<1024;j++){
g[j]=f[j];
g[j]<<=v;// here g In initial state
}
for(int j=0;j<1024;j++){
f[j]|=g[j^m1];// here f For the last state, that is (j^m1)^m1==j notes :“()” Inside is the initial state
}
}
int ans=-1;
for(int i=0;i<1024;i++){
if(f[i][m]) ans=i;
}
cout<<ans<<endl;
}
return 0;
}边栏推荐
- Crazy God redis notes 11
- Mysqlworkbench performance analysis tool -- Performance dashboard
- Ionic4 learning notes 11 - popular goods display of an East Project
- PCI express physical layer - electrical part
- Zip compression and decompression
- CF. Bits And Pieces(子集状压dp + 剪枝)
- 今日睡眠质量记录79分
- Wechat applet reverse
- Thread lifecycle and basic methods
- Show or hide password plaintext + password box verification information
猜你喜欢
随机推荐
2022暑期杭电多校第一场1012Alice and Bob(博弈论)
[wechat applet development] custom tabbar case (custom message 99 + little hearts)
National vocational college skills competition network security competition -- detailed explanation of Apache security configuration
leetcode-记忆化深搜/动态规划v2
Typora user manual
We have to understand the four scopes: application, session, request and page
Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag
PWN learning
Sqoop
2022杭电多校第一场Dragon slayer(dfs+状态压缩)
6. How to add an array in Es5?
Analysis of dropout principle in deep learning
今日睡眠质量记录79分
L4L7负载均衡
Leetcode memory deep search / dynamic planning V2
Vsftpd2.3.4 port penetration 6200 IRC_ 3281_ backdoor
Principle and application of database
Show or hide password plaintext + password box verification information
Understand corners_ Align, two perspectives for viewing pixels
微信小程序逆向









