线性基学习
先膜一下mona,感谢他生动的讲解……Orz
然后
这哥们讲的不错
我的板子
第一个
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iomanip>
#include<algorithm>
#include<ctime>
#include<queue>
#include<stack>
#include<vector>
#define rg register
#define il inline
#define lst long long
#define ldb long double
#define N 55
using namespace std;
const int Inf=1e9;
int n;
lst p[N];
il lst read()
{
rg lst s=0,m=0;rg char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')m=1;ch=getchar();}
while(ch>='0'&&ch<='9')s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
return m?-s:s;
}
il void Insert(rg lst x)
{
for(rg int i=50;i>=0;--i)
{
if(!(x&(1ll<<i)))continue;
if(!p[i])p[i]=x;
x^=p[i];
}
}
il lst Query(rg lst x)
{
for(rg int i=50;i>=0;--i)
x=max(x,x^p[i]);
return x;
}
int main()
{
n=read();
for(rg int i=1;i<=n;++i)
Insert(read());
printf("%lld
",Query(0));
return 0;
}
第二个……
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iomanip>
#include<algorithm>
#include<ctime>
#include<queue>
#include<stack>
#include<vector>
#define rg register
#define il inline
#define lst long long
#define ldb long double
#define N 55
#define mod 2008
using namespace std;
const int Inf=1e9;
int n,m,ans;
lst p[N];
char light[N];
il int read()
{
rg int s=0,m=0;rg char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')m=1;ch=getchar();}
while(ch>='0'&&ch<='9')s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
return m?-s:s;
}
il void Insert(rg lst x)
{
for(rg int i=50;i>=0;--i)
{
if(!(x&(1ll<<i)))continue;
if(!p[i])p[i]=x;
x^=p[i];
}
}
il lst qpow(rg int a,rg int b)
{
rg lst base=a,res=1;
while(b)
{
if(b&1)res=(res*base)%mod;
base=(base*base)%mod;
b>>=1;
}
return res;
}
int main()
{
n=read(),m=read();
for(rg int i=1;i<=m;++i)
{
scanf("%s",light);
rg lst ss=0;
for(rg int j=0;j<n;++j)
ss=ss*2+(light[j]=='O'?1:0);
Insert(ss);
}
for(rg int i=50;i>=0;--i)
if(p[i])ans++;
printf("%lld
",qpow(2,ans));
return 0;
}
题单(没错,xzy的)
- [x] ※【模板】线性基 https://www.luogu.org/problemnew/show/P3812
- [ ] [BeiJing2011] 元素 http://www.lydsy.com/JudgeOnline/problem.php?id=2460
- [ ] [CQOI2013] 新Nim游戏 https://www.luogu.org/problemnew/show/P4301
- [ ] ※[WC2011] 最大XOR和路径 https://www.luogu.org/problemnew/show/P4151
- [ ] [SCOI2016] 幸运数字 https://www.luogu.org/problemnew/show/P3292
- [ ] [BZOJ3811] 玛里苟斯 http://www.lydsy.com/JudgeOnline/problem.php?id=3811
- [ ] [BZOJ2844] albus就是要第一个出场 http://www.lydsy.com/JudgeOnline/problem.php?id=2844
- [ ] ※[HDU2949] XOR https://vjudge.net/problem/HDU-3949