bzoj2844
http://www.lydsy.com/JudgeOnline/problem.php?id=2844
线性基。。。
先把线性基搞出来,然后不断逼近答案,如果这个基比答案小了,那么说明要加上,同时加上贡献:现在的位i +1<<(now-i) 为什么呢,我是这样理解的:一个数分两种情况:选这位和不选这位,如果前面选的位和当前q不同的话,那么前面已经统计过答案了,每次统计答案都是当已经选的数是q的一个子集。我们统计的答案是不选这个位,不选的话,肯定q小,那么这样的数有1<<(now-i)个,因为后面有now-i个基。
然后还要+1,因为我们只统计了比这个数小的数的个数。还要乘上2^(n-now),因为前面now个数已经足够构成基底,那么后面n-now个数肯定会重复。这样会复制2^(n-now)个数。
还有一种解释方法:因为后面都被消成0了,所以选不选都没关系,又因为后面每个a的组合都不一样,和前面搭配都不一样,所以可以。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = , mod = ;
int n, now;
ll q;
ll a[N], bin[];
void gauss()
{
now = ;
for(int i = ; i >= ; --i)
{
int x = now;
while(x <= n && !(a[x] & bin[i])) ++x; //没有这位
if(x == n + ) continue;
swap(a[now], a[x]); // 消去这位其他的1
for(int j = ; j <= n; ++j) if(j != now && a[j] & bin[i]) a[j] ^= a[now];
++now;
}
--now;
}
int main()
{
bin[] = ; for(int i = ; i <= ; ++i) bin[i] = bin[i - ] * ;
scanf("%d", &n);
for(int i = ; i <= n; ++i) scanf("%d", &a[i]);
scanf("%d", &q);
gauss();
ll ans = , val = ;
for(int i = ; i <= now; ++i) if((val ^ a[i]) <= q)
{
val ^= a[i];
ans += bin[now - i] % mod;
}
for(int i = ; i <= n - now; ++i) ans = (ans << ) % mod;
++ans;
printf("%lld\n", (ans % mod + mod) % mod);
return ;
}
bzoj2844的更多相关文章
- CF895C: Square Subsets && 【BZOJ2844】albus就是要第一个出场
CF895C: Square Subsets && [BZOJ2844]albus就是要第一个出场 这两道题很类似,都是线性基的计数问题,解题的核心思想也一样. CF895C Squa ...
- 【bzoj2844】 albus就是要第一个出场
http://www.lydsy.com/JudgeOnline/problem.php?id=2844 (题目链接) 题意 给出${n}$个数,它们可以异或出${n^2}$个数,将这些数从小到大排列 ...
- 【BZOJ2844】albus就是要第一个出场 高斯消元求线性基
[BZOJ2844]albus就是要第一个出场 Description 已知一个长度为n的正整数序列A(下标从1开始), 令 S = { x | 1 <= x <= n }, S 的幂集2 ...
- BZOJ2844: albus就是要第一个出场
Description 已知一个长度为n的正整数序列A(下标从1开始), 令 S = { x | 1 <= x <= n }, S 的幂集2^S定义为S 所有子集构成的集合. 定义映射 f ...
- bzoj千题计划195:bzoj2844: albus就是要第一个出场
http://www.lydsy.com/JudgeOnline/problem.php?id=2844 题意:给定 n个数,把它的所有子集(可以为空)的异或值从小到大排序得到序列 B,请问 Q 在 ...
- 【bzoj2844】albus就是要第一个出场
Time Limit: 6 Sec Memory Limit: 128 MBSubmit: 2254 Solved: 934[Submit][Status][Discuss] Descriptio ...
- BZOJ2844:albus就是要第一个出场——题解
https://www.lydsy.com/JudgeOnline/problem.php?id=2844 已知一个长度为n的正整数序列A(下标从1开始), 令 S = { x | 1 <= x ...
- BZOJ2844: albus就是要第一个出场(线性基)
Time Limit: 6 Sec Memory Limit: 128 MBSubmit: 2054 Solved: 850[Submit][Status][Discuss] Descriptio ...
- 【贪心】【线性基】bzoj2844 albus就是要第一个出场
引用题解:http://blog.csdn.net/PoPoQQQ/article/details/39829237 注意评论区. #include<cstdio> using names ...
- 【线性基】bzoj2844: albus就是要第一个出场
线性基求可重rank 题目描述 给定 n 个数 $\{ a_i \}$ ,以及数 $x$. 将 $\{ a_i \}$ 的所有子集(包括空集)的异或值从小到大排序,得到 $\{ b_i \} $. ...
随机推荐
- 01java基础
01.java基础-18/07/09 1.System.out.print();和System.out.println();的区别是什么 System.out.println();打印的时候自带了换行 ...
- 【汇总】java中数组的声明、初始化及遍历
java中数组用来存储固定大小的同类型元素 一维数组: 1.数组的声明: //声明一维数组,推荐用第一种 int[] a; int b[]; 2.数据的初始化:有三种初始化方式 (1).静态初始化 / ...
- mysql批量替换某个字段的部分内容
举例说明 有数据表person,结构如下 id name urls 1 张三 xh.jpg 2 李四 xh.jpg 3 王五 3.jpg 需求:将urls字段中的xh替换为id字段的值 语句: UPD ...
- Ubuntu notes
ubuntu notes Table of Contents 1. backup data 2. Basics Ubuntu 3. Install, uninstall packages 4. Bas ...
- springcloud(十):熔断监控Hystrix Dashboard
申明: 这里比较坑爹,大家写的时候要小心,这里和springboot的版本有关系哈,我使用的是2.0 版本,要么调频为1.5 版本,要么使用其他方式 解决错误,我选择了还是用2.0 ...
- So easy
Problem Description Small W gets two files. There are n integers in each file. Small W wants to know ...
- sharepoint第三方程序认证尝试失败记录
本来想用REST服务开发第三方的插件的,下面的文章说明REST API是非常好用的 https://technet.microsoft.com/zh-cn/library/jj164022(v=off ...
- spring-cloud-starter-ribbon提供客户端的软件负载均衡算法
Ribbon是什么? Ribbon是Netflix发布的开源项目,主要功能是提供客户端的软件负载均衡算法,将Netflix的中间层服务连接在一起.Ribbon客户端组件提供一系列完善的配置项如连接超时 ...
- redis sentinel集群配置及haproxy配置
ip分布情况: sentinel-1/redis 主 10.11.11.5 sentinel-2/redis 从 10.11.11.7 sentinel-3/redis 从 10.11.11.8 ha ...
- VCS 一次使用。
One database was down today. So I login the server try to check and fix it. I found the Oracle home ...