2025寒训:寒末下午 Day 3 专题:线性基
线性空间 \(W\)
- \(\ x\in W \to kx\in W\qquad F_2:\ k=0,1\)
- \(0\in W\)
- \(x\in W,\ y\in W\to x+y\in W\)
线性有/无关组
\(S\) 中存在子集和为 0 的有关,否则无关
基
极大的线性无关组
\(span(S)\)
求最小的 \(W\),使 \(S\in W\)
求解
- 高斯消元
- 倍增拆位法(推荐)
具体见代码
模版代码 P3812【模板】线性基
#include<bits/stdc++.h>
using namespace std;
#define int long long
int t[55];//桶
void ins(int x)//加入一个数
{
for(int i = 50; i >= 0; i --)
{
if(x & (1ll << i))
{
if(!t[i])
{
t[i] = x;
break;
}
else
{
x ^= t[i];
}
}
}
}
void erase()//化简基
{
for(int i = 0; i <= 50; i ++)
{
for(int j = i + 1; j <= 50; j ++)
{
if(t[j] >> i & 1ll)
{
t[j] ^= t[i];//消除相同的位
}
}
}
}
signed main()
{
int n;
long long x;
cin >> n;
for(int i = 1; i <= n; i ++)
{
cin >> x;
ins(x);
}
erase();
long long ans = 0;
for(int i = 0; i <= 50; i ++)
{
ans ^= t[i];
}
cout << ans;
return 0;
}
P4869 的结论
简化基从小到大排序后为 \(c_0,c_1\dots c_{m-1}\)
令 \(x=2^{a_1}+2^{a_2}+\dots+2^{a_t}\),\(f(x)=c_{a_1}\oplus c_{a_2}\oplus\dots\oplus c_{a_t}\)
结论:\(0\le x<y\le 2^m,\ f(x)<f(y)\)
另一个结论:\(n\) 个数组成大小为 \(s\) 的线性基,则能构成 \(2^s\) 种不同的数,每个数出现 \(2^{n−s}\) 次
hello, I'm yuzihang, if you need to copy this, please quote this url: https://www.cnblogs.com/yuzihang/p/18715255

浙公网安备 33010602011771号