HDU 1874 Good Luck in CET-4 Everybody!

HDU_1874

    终于找到了一个题目练了一下刚刚学习的用SG函数求解的方式,推荐一篇讲SG函数入门知识的博客:http://www.cnblogs.com/Knuth/archive/2009/09/05/1561007.html

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define MAXD 1010
int d[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024};
int N, sg[MAXD];
int dfs(int n)
{
int i, j, k, h[15], rear = 0;
if(sg[n] != -1)
return sg[n];
memset(h, 0, sizeof(h));
for(i = 0; i < 10 && d[i] <= n; i ++)
h[dfs(n - d[i])] = 1;
for(i = 0; h[i]; i ++);
return sg[n] = i;
}
void solve()
{
int i, j, k;
memset(sg + 1, -1, sizeof(sg[0]) * N);
sg[0] = 0;
if(dfs(N) == 0)
printf("Cici\n");
else
printf("Kiki\n");
}
int main()
{
while(scanf("%d", &N) == 1)
{
solve();
}
return 0;
}


你可能感兴趣的:(body)