BZOJ2844 albus就是要第一个出场

本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作。

 

 

本文作者:ljh2000
作者博客:http://www.cnblogs.com/ljh2000-jump/
转载请注明出处,侵权必究,保留最终解释权!

 

题目链接:BZOJ2844

正解:线性基

解题报告:

  $ZJOI2017$的$day1$前一晚复习线性基模板…现在补一发题解。

  考虑一个结论,对于一个$n$个数构成的基,有$k$个向量,那么原来的$n$个数能构成的所有数中,每个值都出现了$2^{n-k}$次,似乎想想还是很有道理的?

  那么构出线性基,按位统计就好了。

 

//It is made by ljh2000
//有志者,事竟成,破釜沉舟,百二秦关终属楚;苦心人,天不负,卧薪尝胆,三千越甲可吞吴。
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <complex>
#include <bitset>
using namespace std;
typedef long long LL;
typedef long double LB;
typedef complex<double> C;
const double pi = acos(-1);
const int mod = 10086;
int n,q,a[45],cnt,m,ans,dui[45];
 
inline int getint(){
    int w=0,q=0; char c=getchar(); while((c<'0'||c>'9') && c!='-') c=getchar();
    if(c=='-') q=1,c=getchar(); while (c>='0'&&c<='9') w=w*10+c-'0',c=getchar(); return q?-w:w;
}

inline LL fast_pow(LL x,LL y){
	LL r=1;
	while(y>0) {
		if(y&1) r*=x,r%=mod;
		x*=x; x%=mod;
		y>>=1;
	}
	return r;
}
 
inline void work(){
	n=getint(); int x;
	for(int i=1;i<=n;i++) {
		x=getint();
		for(int j=31;j>=0;j--) {
			if(!(x>>j)) continue;
			if(!a[j]) { a[j]=x; cnt++; break; }
			x^=a[j];
		}
	}

	q=getint(); int cc=-1; for(int i=0;i<=31;i++) if(a[i]>0) dui[++cc]=i;

	for(int i=0;i<=cc;i++){
		if(!( (q>>dui[i])&1 )/*!!!*/) continue;
		ans+=(1LL<<i)%mod;
		ans%=mod;
	}
	for(int i=n-cnt;i>=1;i--) ans<<=1,ans%=mod;
	ans++; ans%=mod;
	printf("%d",ans);
}
 
int main()
{
    work();
    return 0;
}
//有志者,事竟成,破釜沉舟,百二秦关终属楚;苦心人,天不负,卧薪尝胆,三千越甲可吞吴。

  

posted @ 2017-03-24 19:46  ljh_2000  阅读(666)  评论(0编辑  收藏  举报