当前位置:网站首页>杭电多校第一场第三题 Backpack(异或dp+bitset)
杭电多校第一场第三题 Backpack(异或dp+bitset)
2022-07-24 18:36:00 【愚者的黄昏】
爱丽丝有n项目,每个项目都有一个卷v我和值w我.
是否可以从n个项目中选择多个项目,以使背包完全装满(即体积的总和等于背包容量)?如果是这样,当背包装满时,背包中物品值的最大异或总和是多少?
每个测试用例的第一行包含 2 个整数n,m(1≤n,m<2^10)— 物品数量,背包容量。
下一个n行,每行包含 2 个整数v我,w我(1≤v我,w我<2^10)— 项目的数量和价值。
输出
#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;//此时g为初状态
}
for(int j=0;j<1024;j++){
f[j]|=g[j^m1];//此时f为末状态也就是(j^m1)^m1==j 注:“()”内为初状态
}
}
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
- Ionic4 learning notes 9 -- an east project 01
- 4. Basic type and reference type?
- 引发0xC0000005内存违例几种可能原因分析
- Type-C PD protocol chip while charging and listening
- National vocational college skills competition network security competition -- detailed explanation of Apache security configuration
- 6126. Design food scoring system
- MySQL configuration file
- Sword finger offer 21. adjust the array order so that odd numbers precede even numbers
- 04 distributed resource management system yarn
猜你喜欢

Mysqlworkbench performance analysis tool -- Performance dashboard

9. BOM object?

C Programming classic tutorial

The 5th Digital China Construction summit opened in Fuzhou, Fujian

今日睡眠质量记录79分

Create parent-child projects in clion (cmake tool) and introduce the method of third-party libraries

Valentine's Day gift ----- use her photos and our chat records to generate word clouds~

Vsftpd2.3.4 port penetration 6200 IRC_ 3281_ backdoor

初识Pytorch和Pytorch环境配置

Mid year inventory | in 2022, PAAS will be upgraded again
随机推荐
Typora is still the most beautiful and beautiful document editing artifact of yyds in my heart. I believe you will never abandon it
Variable and immutable data types
Pytoch's journey 1: linear model
[record of question brushing] 20. Valid brackets
Traversal and splicing of strings
[Tkinter] common components (II)
奶头乐理论介绍及个人感悟
线段树合并板子
Type-C PD protocol chip while charging and listening
L4l7 load balancing
Four ways of simple interest mode
6. How to add an array in Es5?
怎么解决idea中yaml无法识别或者飘红?
The assignment and answer of the "Cyberspace Security" competition of the 2020 secondary vocational group in Zhejiang Province (flag)
Revocable search board
CF. Bits And Pieces(子集状压dp + 剪枝)
[wechat applet development] custom tabbar case (custom message 99 + little hearts)
理解corners_align,两种看待像素的视角
ORM introduction and database operation
Matlab simulation of drawing circle on sphere