题目
我是个十分擅长于背公式的选手。
直接
f
[
s
t
a
]
f[sta]
f[sta]表示
s
t
a
sta
sta集合的未被拿出。
f
[
s
t
a
]
=
m
e
x
(
⋃
r
s
t
a
⊂
s
t
a
f
[
r
s
t
a
]
x
o
r
s
u
m
x
o
r
[
s
t
a
−
r
s
t
a
]
)
f[sta] = mex(\bigcup_{rsta \subset sta} f[rsta]\ xor\ sumxor[sta-rsta])
f[sta]=mex(⋃rsta⊂staf[rsta] xor sumxor[sta−rsta])
s
u
m
x
o
r
[
s
t
a
]
=
X
O
R
i
∈
s
t
a
a
[
i
]
sumxor[sta] = XOR_{i \in sta} a[i]
sumxor[sta]=XORi∈staa[i]
直接SG硬上。
AC Code(3780 ms):
#include<bits/stdc++.h>
#define maxn 14
#define maxm 200005
using namespace std;
int n,a[maxn],f[1<<14],sum[1<<14],lg[1<<14];
int vis[maxm],tim;
int ser(int nsta){
if(f[nsta]!=-1) return f[nsta];
for(int tmp=nsta;tmp;tmp=((tmp-1)&nsta))
ser(nsta-tmp);
tim++;
for(int tmp=nsta;tmp;tmp=((tmp-1)&nsta)){
int res = ser(nsta-tmp);
for(int i=0;i<n;i++) if(tmp>>i&1) res^=a[i];
vis[min(res,maxm-1)]=tim;
}
for(f[nsta]=0;vis[f[nsta]]==tim;f[nsta]++);
return f[nsta];
}
char ANS[2][5]={"NO","YES"};
int main(){
for(int i=2;i<(1<<14);i++) lg[i]=lg[i>>1]+1;
for(int T=10;T--;){
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%d",&a[i]);
memset(f,-1,sizeof f);
f[0] = 0;
printf("%s\n",ANS[ser((1<<n)-1)==0]);
}
}
一看status,0ms的大佬???
大佬博客28ms
大佬博客高斯消元0ms
巧妙的构造。