当前位置:网站首页>F - Spices(线性基)
F - Spices(线性基)
2022-06-24 22:57:00 【Harris-H】
F - Spices(线性基)
结论是 [ 1 , 2 n − 1 ] [1,2^n-1] [1,2n−1] 最多选 n n n个数即可表示 [ 1 , 2 n − 1 ] [1,2^n-1] [1,2n−1] ,原理就是线性基。
因为要求 v a l u e value value最小,所以按照价值排序,然后模拟线性基即可。
时间复杂度: O ( n 2 n ) O(n2^n) O(n2n)
#include <bits/stdc++.h>
using i64 = long long;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n;
std::cin >> n;
std::vector<std::pair<int, int>> a((1 << n) - 1);
for (int i = 0; i < (1 << n) - 1; i++) {
int x;
std::cin >> x;
a[i] = {
x, i + 1};
}
std::sort(a.begin(), a.end());
i64 ans = 0;
std::vector<int> t(n);
for (auto [v, x] : a) {
for (int i = 0; i < n; i++) {
if (x >> i & 1) {
if (t[i] == 0) {
ans += v;
t[i] = x;
break;
}
x ^= t[i];
}
}
}
std::cout << ans << "\n";
return 0;
}
边栏推荐
- Lizuofan, co-founder of nonconvex: Taking quantification as his lifelong career
- 都2022年了,你还不了解什么是性能测试?
- Test / development programmers, 30, do you feel confused? And where to go
- EasyCVR平台EHOME协议接入,视频播放出现断流是什么原因?
- Application of TSDB in civil aircraft industry
- mysql命令备份
- 股票开账户如何优惠开户?手机开户是安全么?
- 当一个接口出现异常时候,你是如何分析异常的?
- Are programmers from Huawei, Alibaba and other large manufacturers really easy to find?
- Intégration de la plate - forme de test continu open source de metersphere avec Alibaba Cloud Effect devops
猜你喜欢

Left hand dreams right hand responsibilities GAC Honda not only pays attention to sales but also children's safety

谈谈飞书对开发工作的优势 | 社区征文

File system - basic knowledge of disk and detailed introduction to FAT32 file system

Application of TSDB in civil aircraft industry

DDD concept is complex and difficult to understand. How to design code implementation model in practice?

3年测试经验,连简历上真正需要什么都没搞明白,张口就要20k?

qt打包exe文件,解决“无法定位程序输入点_ZdaPvj于动态链接库Qt5Cored.dll”

EasyCVR国标协议接入的通道,在线通道部分播放异常是什么原因?
![[live review] battle code pioneer phase 7: how third-party application developers contribute to open source](/img/ad/26a302ca724177e37fe123f8b75e4e.png)
[live review] battle code pioneer phase 7: how third-party application developers contribute to open source

Experience of epidemic prevention and control, home office and online teaching | community essay solicitation
随机推荐
华泰证券如何开户能做到万分之一?证券开户安全可靠吗
【STL源码剖析】STL六大组件功能与运用(目录)
Intranet learning notes (6)
进入阿里做测试员遥不可及?这里或许有你想要的答案
It's 2022, and you still don't know what performance testing is?
【Proteus仿真】Arduino UNO+数码管显示4x4键盘矩阵按键
ProcessOn制作ER过程(自定义)
ida中交叉引用的解析
How can Huatai Securities open an account to achieve one in ten thousand? Are securities accounts safe and reliable
Talking about the advantages of flying book in development work | community essay solicitation
When an interface has an exception, how do you analyze the exception?
Beescms website penetration test and repair comments "suggestions collection"
Android物联网应用程序开发(智慧园区)—— 设置传感器阈值对话框界面
Explanation of FTP protocol
【FPGA】串口以命令控制温度采集
|How to analyze bugs? Professional summary and analysis
Logminer database log mining
Investigation on key threats of cloud computing applications in 2022
内网学习笔记(6)
How to get the picture outside the chain - Netease photo album [easy to understand]