2019 牛客暑期多校 第一场 H XOR (线性基)
2024-10-07 16:45:27
题目:https://ac.nowcoder.com/acm/contest/881/H
题意:求一个集合内所有子集异或和为0的长度之和
思路:首先集合内异或和,这是线性基的一个明显标志,然后我们不管怎么样先求出一个基A,秩为r
我们枚举基外的数,每个数的贡献是 2^(n-r-1) ,为什么呢,因为其余数我都可以选择选或不选,无论什么组合,我都可以在基内表示出来,那么就肯定异或为0
我们再来枚举基A内的数,我枚举当前数的时候把其余元素再求一遍基,然后以上面相同的道理计算贡献,
#include<bits/stdc++.h>
#define maxn 100005
#define mod 1000000007
using namespace std; typedef long long LL; int n, r, tot;
bool vis[maxn];
vector<LL> vec;
LL a[maxn], b[], other[], tmp[]; LL qpow(LL x, int n) {
LL res = ;
while(n) {
if(n & ) res = res * x % mod;
x = x * x % mod;
n >>= ;
}
return res;
} bool ins(LL x, LL base[]) {
for(int i = ; i >= ; --i) {
if(x & (1LL << i)) {
if(base[i]) x ^= base[i];
else {
base[i] = x;
return true;
}
}
}
return false;
} int main() {
while(~scanf("%d", &n)) {
r = tot = ;
vec.clear();
for(int i = ; i <= ; ++i) b[i] = other[i] = ;
for(int i = ; i <= n; ++i) {
scanf("%lld", &a[i]);
vis[i] = ;
if(ins(a[i], b)) vis[i] = , ++r, vec.emplace_back(a[i]);
}
if(r == n) {
printf("0\n");
continue;
}
LL ans = qpow(, n - r - ) * (n - r) % mod;;
for(int i = ; i <= n; ++i) {
if(vis[i]) continue;
ins(a[i], other);
}
for(int i = ; i < vec.size(); ++i) {
tot = ;
for(int j = ; j <= ; ++j) tmp[j] = ;
for(int j = ; j < vec.size(); ++j) {
if(i == j) continue;
if(ins(vec[j], tmp)) ++tot;
}
for(int j = ; j <= ; ++j) {
if(other[j] && ins(other[j], tmp)) ++tot;
}
if(!ins(vec[i], tmp)) {
ans = (ans + qpow(, n - tot - )) % mod;
}
}
printf("%lld\n", ans);
}
return ;
}
最新文章
- git将本地代码 和服务器git@osc 上的代码 关联
- Java Servlet(七):JavaWeb MVC 操作(jdk7+tomcat7+eclipse)
- iOS 中的字体预览
- 【转】Web UI自动化测试原理
- lib库依赖解决
- Delphi-Delete 过程
- 转载:/etc/resolv.conf的作用
- Head First HTML与CSS — 布局与定位
- 第三章 AOP 编程选择
- Spring Boot 系列教程16-数据国际化
- Google Chrome Plus&mdash;&mdash;绿色便携多功能谷歌浏览器
- 快递单号查询免费api接口(PHP示例)
- 剑指offer 11:二进制中 1 的个数
- git 创建标签和删除标签
- Python学习(四)数据结构 —— bool
- 使用jxls技术导入Excel模版数据(转自其他博客)
- 菜单 &; 工具栏 &; 状态栏
- Jenkins任务优先分配到原来的执行节点上
- ABAP F4使用总结!!
- stl_multiset.h
热门文章
- paper 159:文章解读:From Facial Parts Responses to Face Detection: A Deep Learning Approach--2015ICCV
- IPC机制总结
- JAVA(JDK,JRE)更改目录安装及环境变量配置
- Critical Links
- SQLmap注入
- Spring-Boot";原生态";的logback
- js中的投掷筛子的小游戏
- 【读书笔记】:MIT线性代数(2):Vector Spaces and Subspaces
- 为GitLab帐号添加SSH keys并连接GitLab
- 转 LoadRunner错误处理函数