首先求出线性基,并且进一步尽可能的使的p[i]除了第i位是1以外,取余全0,尽量使得除了主对角线其余元素都为0;
之后判断线性基的秩,若秩!=元素个数,说明元素之间异或会出现0的情况,那么需要将k-1,因为此时剩余的非零向量间是无法异或出0的情况的,0是最小的异或值;
假设秩为x,那么向量间相互异或的可能情况有1<<x种,若k>=(1<<x),则说明不可异或出,否则将k二进制拆分,若这一位为1则异或对应的p[i];
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const double epos=1e-8;
const int maxn=1e4+7;
//int b[maxn];
ll a[maxn];
ll p[64];
//int hhh[maxn][64];
void Linear_basis(int n){
//for(int i=1;i<=n;++i)
// a[i]=b[i];
memset(p,0,sizeof(p));
//memset(hhh,0,sizeof(hhh));
for(int i=1;i<=n;++i)
for(int j=63;j>=0;--j)
if(a[i]&(1LL<<j)){
if(p[j]) a[i]^=p[j];
else{ p[j]=a[i];brea