当前位置:网站首页>[diary of supplementary questions] [2022 Hangdian summer school 1] c-backpack
[diary of supplementary questions] [2022 Hangdian summer school 1] c-backpack
2022-07-24 02:25:00 【cls1277】
Pro
https://acm.hdu.edu.cn/showproblem.php?pid=7140
Sol
f i , j , k f_{i,j,k} fi,j,k Before presentation i Items , XOR sum j, The volume is k Whether there is a plan for
Then the state transfer equation is f i , j , k = f i − 1 , j , k ∣ f i − 1 , j ⊕ v , k − w f_{i,j,k}=f_{i-1,j,k}|f_{i-1,j\oplus v,k-w} fi,j,k=fi−1,j,k∣fi−1,j⊕v,k−w
Use the scrolling array to roll out the first dimension , use bitset Optimize the last dimension
About g[j]=f[j]<<x explain : The use of shift left here can be understood as , When the first i i i Secondary mobility v i v_i vi when , The final total movement is ∑ i = 1 n v i x i , x i = 0 / 1 \sum_{i=1}^n v_ix_i,x_i={0/1} ∑i=1nvixi,xi=0/1. If the total number of moves is m m m, That is to say bitset Of the m m m Position as 1, It means that it can just fill the whole backpack .
Code
//By cls1277
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define Fo(i,a,b) for(LL i=(a); i<=(b); i++)
#define Ro(i,b,a) for(LL i=(b); i>=(a); i--)
#define Eo(i,x,_) for(LL i=head[x]; i; i=_[i].next)
#define Ms(a,b) memset((a),(b),sizeof(a))
#define endl '\n'
const LL maxn = 1030;
bitset<maxn> f[maxn], g[maxn];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef DEBUG
freopen("data.txt","r",stdin);
#endif
LL t; cin>>t;
while(t--) {
LL n, m; cin>>n>>m;
Fo(i,0,1023) f[i].reset();
f[0][0] = 1;
Fo(i,1,n) {
LL x, y; cin>>x>>y;
Fo(j,0,1023) g[j]=f[j]<<x;
Fo(j,0,1023) f[j]|=g[j^y];
}
LL ans = -1;
Ro(i,1023,0) {
if(f[i][m]) {
ans = i;
break;
}
}
cout<<ans<<endl;
}
return 0;
}
边栏推荐
- Tdengine helps Siemens' lightweight digital solution simicas simplify data processing process
- Idea's gradle project Chinese garbled
- Qt开发串口通讯软件中的数据转换问题:读取时_QByteArray转string;发送时_数据格式;int转16进制格式string;string中截取字符;16进制数加法;string转ByteAr
- STM32概念和安装【第一天】
- Ggplot2 displays png
- 营员招募|心怀世界的AI青年们,联合国需要你为可持续发展助力!
- What's new in the ranking list in July? This language is invincible?
- Pbootcms template calls the tag ordinal number from 2 or automatic number
- 【补题日记】[2022牛客暑期多校1]J-Serval and Essay
- 【数据集】——flyingthings3d光流部分数据集下载
猜你喜欢
![[C language] preprocessing details](/img/c3/861165ce20c135f4feedee1f112261.png)
[C language] preprocessing details

Solve the problem that the script tag is written in front of the element node and cannot get the element node

图解数组和链表详细对比,性能测试

pbootcms模板调用标签序数从2开始或者自动数开始

关于 SAP 电商云 Spartacus UI Transfer State 冗余 API 请求发送的讨论

Tdengine helps Siemens' lightweight digital solution simicas simplify data processing process
![[jailhouse article] virtualization over multiprocessor system on chip an enabling paradigm for](/img/7b/95df873bfcad6b14c009d2681cf2f6.png)
[jailhouse article] virtualization over multiprocessor system on chip an enabling paradigm for

5年接觸近百比特老板,身為獵頭的我,發現昇職的秘密不過4個字

Enter cnpm -v and cnpm appears: the file c:\users\19457\appdata\roaming\npm\cnpm.ps1 cannot be loaded because running scripts is prohibited on this system.
![【补题日记】[2022牛客暑期多校1]I-Chiitoitsu](/img/be/47b8a86399f760e7cd6181528884c6.png)
【补题日记】[2022牛客暑期多校1]I-Chiitoitsu
随机推荐
Today's code farmer girl learned about the express framework under node
Qml- use listview to build a three-level treeview architecture
Redraw the button and make your own circular LED indicator
Login with a third-party account
C - structure
Crud operation of mongodb (2)
Go basic notes_ 5_ Array slice
This article shows you how to use SQL to process weekly report data
Jmeter+influxdb+grafana pressure measurement real-time monitoring platform construction
无需编码,自动实现“异步 Request-Reply”模式
营员招募|心怀世界的AI青年们,联合国需要你为可持续发展助力!
【补题日记】[2022杭电暑期多校1]B-Dragon slayer
网络协议详解 :UDP
组件el-scrollbar的使用
Idea's gradle project Chinese garbled
MySQL---four JDBC
Visual full link log tracking
1000个Okaleido Tiger首发上线Binance NFT,引发抢购热潮
How to judge null for different types of fields, sets, lists / sets / maps, and objects
奔走相告,行情与量化页面功能优化!股票量化分析工具QTYX-V2.4.5