http://acm.hdu.edu.cn/showproblem.php?pid=1847

如果j-A[i]是必败态,j就是必胜态,显然0必败,一个dp的过程

#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int A[15], win[1005];

int main() {
    A[0] = 1;
    int k;
    for(int i = 1; ; i++) {
        A[i] = A[i-1] * 2;
        if(A[i] >= 1000) {
            k = i;
            break;
        }
    }
    int n;
    while(~scanf("%d", &n)) {
        for(int j = 1; j <= n; j++) {
            for(int i = 0; i < k; i++) {
                if(A[i] <= j && !win[j-A[i]])
                    win[j] = 1;
            }
        }
        if(win[n]) puts("Kiki");
        else puts("Cici");
    }
    return 0;
}
View Code