题解:P11713 [清华集训 2014] 玛里苟斯
idea from hehezhou
hehezhou上课讲线性代数讲了这题,正好我来写一篇题解。
这题有两个运算,异或和乘方,显然我们不太能把题目要求的式子拆开,由于是先异或再乘方,所以我们先考虑里面的
而处理异或我们有一个数据结构叫做异或线性基,把
具体细节可看代码。
#include<bits/stdc++.h>
using namespace std;
#define __MY_TEST__ 0
inline unsigned long long read()
{
int f=1;
unsigned long long re=0;
char ch=getchar();
while(!isdigit(ch)){ if(ch=='-') f=-1; ch=getchar();}
while( isdigit(ch)) re=(re<<3)+(re<<1)+(ch^'0'),ch=getchar();
return re*f;
}
unsigned long long z[105],aans;
int maxn,k,ans[6],t[6];
void dfs(int u)
{
if(u==k)
{
int x,sum=1;
memset(t,0,sizeof t);
for(int i=0;i<=maxn;i++)
{
if(z[i])
{
x=0;
for(int j=0;j<k;j++) x|=(z[i]&(1ull<<ans[j])?1:0)<<j;
for(int j=k;~j;j--) if(x&(1<<j))
{
if(!t[j]) t[j]=x,sum--;
x^=t[j];
}
}
}
x=(1<<k)-1;
for(int i=k;~i;sum+=ans[i],i--) if(x&(1<<i)) x^=t[i];
if(!x) aans+=1ull<<sum;
return ;
}
for(int i=0;i<=maxn;i++) ans[u]=i,dfs(u+1);
}
signed main()
{
#if __MY_TEST__
freopen(".in","r",stdin);
freopen(".out","w",stdout);
#endif
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int n=read();k=read();
for(int i=1;i<=n;i++)
{
unsigned long long t=read();
for(int j=63;~j;j--) if(t&(1ull<<j))
{
if(z[j]) t^=z[j]; else z[j]=t,t=0;
}
}
maxn=63;
while(!z[maxn]) maxn--;
dfs(0);
cout<<aans/2;
if(aans&1) cout<<".5";
}