[洛谷P3857][TJOI2008]彩灯

题目大意:有$n$盏灯,$m$个开关($n,m\leqslant 50$),每个开关可以控制的灯用一串$OX$串表示,$O$表示可以控制(即按一下,灯的状态改变),$X$表示不可以控制,问有多少种灯的亮暗状态

题解:线性基,线性基有一个性质,插入的数的任意一个集合的异或值都不同,所以若插入了$k$个数,答案就是$2^k$

卡点:

 

C++ Code:

#include <cstdio>
#include <cctype>
int n, m;
long long p[55], x, ans = 1;
inline long long read() {
	long long x;
	char t = getchar();
	while (isspace(t)) t = getchar();
	for (x = (t == 'O'), t = getchar(); !isspace(t); t = getchar()) x = (x << 1ll) + (t == 'O');
	return x;
}
int main() {
	scanf("%d%d", &n, &m);
	while (m --> 0) {
		x = read();
		for (int i = 50; ~i; i--) if (x & 1ll << i) {
			if (p[i]) x ^= p[i];
			else {p[i] = x; ans <<= 1ll; break;}
		}
	}
	printf("%lld\n", ans % 2008);
	return 0;
}

  

posted @ 2018-09-20 16:50  Memory_of_winter  阅读(225)  评论(0编辑  收藏  举报