SG函数

int sg[1000],book[10];
memset(sg, -1, sizeof(sg));
sg[0] = 0;//必败态初始化为0
for (int i = 1; i <= 1000000; i++)
	dfs(i);
int dfs(int x)
{
    if (sg[x] != -1)
		return sg[x];
    memset(book, 0, sizeof(book));
    book[dfs(状态x可以转化成的所有状态)]=1;
    for (int i = 0;; i++)
	{
		if (book[i] == 0)
		{
			sg[x] = i;
			return sg[x];
		}
	}
}
posted on 2022-09-08 19:33  naiji  阅读(23)  评论(0编辑  收藏  举报