题目: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 ;
}

最新文章

  1. git将本地代码 和服务器git@osc 上的代码 关联
  2. Java Servlet(七):JavaWeb MVC 操作(jdk7+tomcat7+eclipse)
  3. iOS 中的字体预览
  4. 【转】Web UI自动化测试原理
  5. lib库依赖解决
  6. Delphi-Delete 过程
  7. 转载:/etc/resolv.conf的作用
  8. Head First HTML与CSS — 布局与定位
  9. 第三章 AOP 编程选择
  10. Spring Boot 系列教程16-数据国际化
  11. Google Chrome Plus&mdash;&mdash;绿色便携多功能谷歌浏览器
  12. 快递单号查询免费api接口(PHP示例)
  13. 剑指offer 11:二进制中 1 的个数
  14. git 创建标签和删除标签
  15. Python学习(四)数据结构 —— bool
  16. 使用jxls技术导入Excel模版数据(转自其他博客)
  17. 菜单 &amp; 工具栏 &amp; 状态栏
  18. Jenkins任务优先分配到原来的执行节点上
  19. ABAP F4使用总结!!
  20. stl_multiset.h

热门文章

  1. paper 159:文章解读:From Facial Parts Responses to Face Detection: A Deep Learning Approach--2015ICCV
  2. IPC机制总结
  3. JAVA(JDK,JRE)更改目录安装及环境变量配置
  4. Critical Links
  5. SQLmap注入
  6. Spring-Boot&quot;原生态&quot;的logback
  7. js中的投掷筛子的小游戏
  8. 【读书笔记】:MIT线性代数(2):Vector Spaces and Subspaces
  9. 为GitLab帐号添加SSH keys并连接GitLab
  10. 转 LoadRunner错误处理函数