P3857. [TJOI2008] 彩灯

\(Solution\)

一道比较模板的线性基,设\(a\)为线性基中元素的个数,那么答为

\[\sum_{i = 0}^a \binom{a}{i} = \sum_{i = 0}^a \binom{a}{i}*1^i*1^{a - i} = (1 + 1)^a = 2^a \]

因为从线性基中取任意个数的元素异或的结果是不同的。

\(Code\)

#include<cstdio>
#define LL long long
using namespace std;
const int P = 2008;
LL p[52],ans = 1; int n,m; char s[52];

void insert(LL x)
{
	for (int i = 50; i >= 0; i--)
	{
		if (!(x >> i)) continue;
		if (!p[i]){p[i] = x,ans = (ans * 2LL) % P; break;}
		x ^= p[i];
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for (int i = 1; i <= m; i++)
	{
		scanf("%s",s); LL S = 0;
		for (int j = 0; j < n; j++)
			if (s[j] == 'O') S |= (1LL << j);
		insert(S);
	}
	printf("%d\n",ans);
}
posted @ 2022-02-10 21:57  RiverSheep  阅读(33)  评论(0)    收藏  举报