本题用了打表的形式,求出了1000内的sg值,非常直接
参考代码(http://www.cnblogs.com/lzsz1212/archive/2012/01/06/2315337.html)
# include <stdio.h> # include <string.h> int sg[10010] ; int k, knum[110] ; int flag[110] ; int met(int n) { int i, ans = 0 ; memset (flag, 0, sizeof(flag)) ; for (i = 0 ; i < k ; i++) if (n - knum[i] >= 0) flag[sg[n - knum[i]]] = 1 ; for (i = 0 ; i <= 101 ; i++) if (flag[i] == 0) return i ; } void Sprague_Grundy() { int i ; for (i = 1 ; i <= 10000 ; i++) sg[i] = met(i) ; } int main () { int i, n, l, num, ans ; while (~scanf ("%d", &k) && k) { for (i = 0 ; i < k ; i++) scanf ("%d", &knum[i]) ; Sprague_Grundy() ; scanf ("%d", &n) ; while (n--) { ans = 0 ; scanf ("%d", &l) ; while (l--) { scanf ("%d", &num) ; ans ^= sg[num] ; } printf (ans == 0 ? "L" : "W") ; } printf ("\n") ; } return 0 ; }