当前位置:网站首页>[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;
}
边栏推荐
- LeetCode 70爬楼梯、199二叉树的右视图、232用栈实现队列、143重排链表
- Research on XMPP service (I)
- 新红包封面平台可搭建分站独立后台的源码
- What is naked SQL? What middleware or plug-in is good for express to operate MySQL?
- Seatunnel architecture
- On Domain Driven Design
- Combined with actual combat, analyze gb/t 28181 (II) -- equipment directory synchronization
- ACM SIGIR 2022 | interpretation of selected papers of meituan technical team
- 【数据集】——flyingthings3d光流部分数据集下载
- The new red envelope cover platform can build the source code of the independent background of the sub station
猜你喜欢

氢能创业大赛 | 国华投资董事长刘小奇:发挥风光氢储融一体化优势 高水平承办创业大赛

Network protocol details: TCP part1

毕业设计校园信息发布平台网站源码

Deliver temperature with science and technology, vivo protects the beauty of biodiversity

Use the pagoda panel to plan tasks and automatically push the website to Baidu for inclusion

Running around, market and quantitative page function optimization! Stock quantitative analysis tool qtyx-v2.4.5

Idea's gradle project Chinese garbled

认识传输层协议—TCP/UDP

奔走相告,行情与量化页面功能优化!股票量化分析工具QTYX-V2.4.5

Pbootcms template calls the tag ordinal number from 2 or automatic number
随机推荐
Writing of graph nodes that trigger different special effects during the day and at night in Tiktok
C - structure
Vue3 uses keep alive to cache pages, but every time you switch the tab to enter the page, it will still enter onmounted, resulting in no caching effect. Why?
我国科学家在高安全量子密钥分发网络方面取得新进展
Leetcode exercise -- two questions about the nearest common ancestor of binary trees
关于缺少编程基础的朋友想转行 ABAP 开发岗提出的一些咨询问题和解答
BPG notes (III)
网络协议详解 :UDP
After five years of contact with nearly 100 bosses, as a headhunter, I found that the secret of promotion was only four words
浅谈领域驱动设计
Graduation design campus information publishing platform website source code
async await详解 & Promise
Async await details & Promise
Redraw the button and make your own circular LED indicator
Tdengine helps Siemens' lightweight digital solution simicas simplify data processing process
Running around, market and quantitative page function optimization! Stock quantitative analysis tool qtyx-v2.4.5
【补题日记】[2022杭电暑期多校1]B-Dragon slayer
【FPGA教程案例38】通信案例8——基于FPGA的串并-并串数据传输
Draw pictures with canvas
Visual full link log tracking