ARC087E

首先建出一棵 01-Trie,容易发现选择一个字符串之后,它的子树和到根节点的链上的节点都不能再选了。

仔细观察一下,发现剩下的树实际上是若干个满二叉树,那么要求出这些满二叉树的 SG 函数。

对于一棵深度为 \(x\) 的满二叉树(令根节点深度为 \(0\)),观察一下,发现:

  • 若取根节点,则整棵树没了,变成先手必败的局面。
  • 若取一个深度为 \(1\) 的点,那么还剩下一棵深度为 \(x-1\) 的满二叉树。
  • 若取一个深度为 \(2\) 的点,那么还剩下两棵深度分别为 \(x-1,x-2\) 的满二叉树。
  • \(\cdots\)
  • 若取一个深度为 \(x\) 的点,那么还剩下 \(x\) 棵深度分别为 \(0,1,\cdots,x-2,x-1\) 的满二叉树。

于是列出式子:

\[SG(x)=\text{mex}\left\{0,SG(x-1),SG(x-1)\oplus SG(x-2),SG(x-1)\oplus\cdots\oplus SG(0)\right\} \]

其中 \(SG(0)=0\)

打表发现 \(SG(x)\) 就是 \(x\)\(\text{lowbit}\)

不会证明()

Code:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100005;
int n; ll L;
char s[N];
int trie[N][2], tot = 1;
int dep[N], vis[N];
ll ans;

void insert() {
	int p = 1, len = strlen(s + 1);
	for (int i = 1; i <= len; ++i) {
		int c = s[i] - '0';
		if (!trie[p][c]) trie[p][c] = ++tot;
		dep[trie[p][c]] = dep[p] + 1, p = trie[p][c];
	}
	vis[p] = 1;
}

ll SG(ll x) { return x & -x; }

void dfs(int p, int len) {
	if (vis[p]) return;
	if (trie[p][0]) dfs(trie[p][0], len + 1); else ans ^= SG(L - len);
	if (trie[p][1]) dfs(trie[p][1], len + 1); else ans ^= SG(L - len);
}

int main() {
	scanf("%d%lld", &n, &L);
	for (int i = 1; i <= n; ++i) scanf("%s", s + 1), insert();
	dfs(1, 0);
	printf("%s", ans ? "Alice" : "Bob");
	return 0;
}
posted @ 2022-11-25 09:30  Kobe303  阅读(12)  评论(0编辑  收藏  举报