当前位置:网站首页>【补题日记】[2022杭电暑期多校1]C-Backpack
【补题日记】[2022杭电暑期多校1]C-Backpack
2022-07-24 02:23:00 【cls1277】
Pro
https://acm.hdu.edu.cn/showproblem.php?pid=7140
Sol
f i , j , k f_{i,j,k} fi,j,k表示前i个物品,异或和为j,体积为k的方案是否存在
则状态转移方程为 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
使用滚动数组将第一维滚掉,用bitset优化掉最后一维
关于下面代码中的g[j]=f[j]<<x说明:此处使用左移可以理解为,当第 i i i次移动 v i v_i vi时,最终总的移动为 ∑ 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。如果总的移动次数为 m m m,也就是bitset的第 m m m位为1,就说明可以恰好装满整个背包。
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;
}
边栏推荐
- MySQL---four JDBC
- 分布式资源管理与任务调度框架Yarn
- Leetcode 70 climbing stairs, 199 right view of binary tree, 232 realizing queue with stack, 143 rearranging linked list
- Halide::Generator生成器使用说明
- Redraw the button and make your own circular LED indicator
- C -- bit operation
- Login with a third-party account
- WordPress website SEO complete tutorial
- Implementation of POP3 client code
- 5年接触近百位老板,身为猎头的我,发现升职的秘密不过4个字
猜你喜欢

One year after graduation, I gave up the internship opportunity and taught myself software testing at home. The internship of my classmates has just ended. I have become a 12K monthly salary testing e
![[C language operation of linked list (initialization, establishment, length calculation, addition, deletion, and output of linked list)]](/img/9b/e5cda39c04d0cc2f69e43c97ee997d.png)
[C language operation of linked list (initialization, establishment, length calculation, addition, deletion, and output of linked list)]

新红包封面平台可搭建分站独立后台的源码

Writing of graph nodes that trigger different special effects during the day and at night in Tiktok

WordPress website SEO complete tutorial

async await详解 & Promise

What's new in the ranking list in July? This language is invincible?

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

認識傳輸層協議—TCP/UDP

Canvas drawing (mouse click to draw and lift to end)
随机推荐
Responsive layout a web page displays different effects on different devices) meta:vp
Build a CPU Simulator
新红包封面平台可搭建分站独立后台的源码
文心大模型扬起新“帆”,产业应用大潮已至
Writing of graph nodes that trigger different special effects during the day and at night in Tiktok
输入cnpm -v出现cnpm : 无法加载文件 C:\Users\19457\AppData\Roaming\npm\cnpm.ps1,因为在此系统上禁止运行脚本。
ACM SIGIR 2022 | interpretation of selected papers of meituan technical team
关于 SAP Fiori 应用的离线使用
程序员必备技能----断点调试(IDEA版)
[重要通知]星球线上培训第三期来袭!讲解如何在QTYX上构建自己的量化策略!...
Quick sort considerations
MySQL---four JDBC
On Domain Driven Design
Summary of the first change to open source middleware keycloak
Wallys/PD-60 802.3AT Input Output802.3AT/AT 85% Efficiency 10/100/1000M GE Surge Protection
Sharing a case of controller restart caused by a CIFS bug in NetApp Fas series
Digicert code signing certificate
BPG notes (III)
Combined with actual combat, analyze gb/t 28181 (II) -- equipment directory synchronization
How to do a good job of accompanying translation