当前位置:网站首页>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;
}边栏推荐
- [today in history] July 24: caldera v. Microsoft; Amd announced its acquisition of ATI; Google launches chromecast
- Leetcode memory deep search / dynamic planning V2
- EasyUI adds row level buttons to the DataGrid
- Ionic4 learning notes 9 -- an east project 01
- 2. JS variable type conversion, automatic conversion, manual conversion, what is the difference between parseint(), parsefloat(), number()?
- 暑期牛客多校1: I Chiitoitsu(期望dp,求逆元)
- PWN learning
- Mysql——》数据类型隐式转换
- 永恒之蓝MS17-010exp复现
- Calling startActivity() from outside of an Activity context requires the FLAG_ ACTIVITY_ NEW_ TASK flag
猜你喜欢

Principle and application of database

理解corners_align,两种看待像素的视角

Leetcode memory deep search / dynamic planning V2

National vocational college skills competition network security competition -- detailed explanation of Apache security configuration

ETL development tool kettle download installation environment construction and use tutorial

Cryptography knowledge - Introduction to encryption -1

Common problems of multithreading and concurrent programming (to be continued)

Why is gradient the fastest changing direction of function

Missing value processing

7. Character coding?
随机推荐
Ionic4 learning notes 12 - a east project grid completes the list of goods
Analysis of dropout principle in deep learning
网络安全80端口—-PHP CGI参数注入执行漏洞
卷积神经网络感受野计算指南
全国职业院校技能大赛网络安全竞赛——Apache安全配置详解
使用 tftp 无法向服务器上传文件问题解决
引发0xC0000005内存违例几种可能原因分析
New stage of investment
Ionic4 Learning Notes 6 -- using native ionic4 components in custom components
L4l7 load balancing
The problem that files cannot be uploaded to the server using TFTP is solved
4. Basic type and reference type?
Inoic4 learning notes 2
Wechat applet reverse
The difference between KIB and MIB and KB and MB
1. Typeof view variable type?
Type-C边充边听PD协议芯片
Some buckles
[wechat applet development] custom tabbar case (custom message 99 + little hearts)
JS to achieve progress steps (small exercise)