当前位置:网站首页>【补题日记】[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;
}
边栏推荐
- After five years of contact with nearly 100 bosses, as a headhunter, I found that the secret of promotion was only four words
- ggplot2显示png
- Brief introduction of tfw6524 perfectly replacing imported pt6524 chip
- Go basic notes_ 5_ Array slice
- 图解数组和链表详细对比,性能测试
- Crud operation of mongodb (2)
- Give me five minutes, give you a "cloud"
- Ggplot2 displays png
- NetApp FAS系列一个CIFS bug引起的控制器重启案例分享
- 5年接觸近百比特老板,身為獵頭的我,發現昇職的秘密不過4個字
猜你喜欢

认识传输层协议—TCP/UDP

Seatunnel architecture

The combination sum of C language power deduction question 39. Backtracking method and traversal method

Performance optimization of wechat applet (subcontracting, operation process details, simplified structure, native component communication)

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,因为在此系统上禁止运行脚本。
![STM32 installation tutorial and j-link burning driver installation tutorial [the next day]](/img/09/def640c771f1b9effaaec3844d4cd3.png)
STM32 installation tutorial and j-link burning driver installation tutorial [the next day]

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

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

Reconnaître le Protocole de couche de transport - TCP / UDP
随机推荐
Small volume stock trading record | based on multi task crawler technology, realize level1 sampling of A-share real-time market
View Binding 混淆问题。我两天都在研究混淆。
Use the pagoda panel to plan tasks and automatically push the website to Baidu for inclusion
wallys/WiFi6 MiniPCIe Module 2T2R2 × 2.4GHz 2x5GHz MT7915 MT7975
pbootcms模板调用标签序数从2开始或者自动数开始
Chapter 9.2 program control of MATLAB
Implementation of POP3 client code
Detailed comparison between graphic array and linked list, performance test
ASP. Net core write a cache attribute tool
Resumption: a deck of cards (54), three people fighting the landlord, what is the probability that the big and small kings are in the same family
Deliver temperature with science and technology, vivo protects the beauty of biodiversity
Solve the problem that the script tag is written in front of the element node and cannot get the element node
hdu-7141 Ball (bitset)
ggplot2显示png
毕业设计校园信息发布平台网站源码
MySQL---four JDBC
[MySQL] character set utf8mb4 cannot store the record of expression stepping on the pit
程序员必备技能----断点调试(IDEA版)
Writing of graph nodes that trigger different special effects during the day and at night in Tiktok
Where is the safest place to open a futures account now with the lowest handling fee?