当前位置:网站首页>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;
}
边栏推荐
- [mobile terminal] design size of mobile phone interface
- Android Internet of things application development (smart Park) - set sensor threshold dialog interface
- 多模态情感识别_多模态融合的情感识别研究「建议收藏」
- When they are in private, they have a sense of propriety
- Please run IDA with elevated permissons for local debugging.
- Kaggle 专利匹配比赛赛后总结
- File system - basic knowledge of disk and detailed introduction to FAT32 file system
- Intégration de la plate - forme de test continu open source de metersphere avec Alibaba Cloud Effect devops
- 非凸联合创始人李佐凡:将量化作为自己的终身事业
- Investigation on key threats of cloud computing applications in 2022
猜你喜欢

探索C语言程序奥秘——C语言程序编译与预处理

Sumati GameFi生态纵览,神奇世界中的元素设计

元宇宙的生态圈

软件测试人员的7个等级,据说只有1%的人能做到级别7

常用的软件测试工具清单,请查收。

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

背了八股文,六月赢麻了……

如何通过EasyCVR接口监测日志观察平台拉流情况?

非凸联合创始人李佐凡:将量化作为自己的终身事业

The ecosystem of the yuan universe
随机推荐
Use of hashcat
Hashcat 的使用
Smartctl opens the device and encounters permission denied problem troubleshooting process record
vim的Dirvish中文文档
泰山OFFICE技术讲座:竖排时中文标点的简单研究
Cusdis - 轻量级、隐私优先的开源评论系统 | 倾城之链
年已过半,年终立的Flag实现了几个?
Specific list of regular and safe domestic stock trading account opening
Is GF futures safe? What do I need to open an account?
Intranet learning notes (6)
Redistemplate operates redis. This article is enough (I) [easy to understand]
Do you know your ABC
记一次beego通过go get命令后找不到bee.exe的坑
02-Epicor二次开发常用代码
TSDB在民机行业中的应用
MeterSphere開源持續測試平臺與阿裏雲雲效DevOps的集成
1-6搭建Win7虚拟机环境
Half of the year has passed. How many flags have been achieved at the end of the year?
MOS tube related knowledge
会自动化—10K,能做自动化—20K,你搞懂自动化测试没有?