比较简单的SG函数题吧
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
const double PI = acos(-1.0);
template <class T> inline T MAX(T a, T b){if (a > b) return a;return b;}
template <class T> inline T MIN(T a, T b){if (a < b) return a;return b;}
const int N = 111;
const int M = 11111;
const LL MOD = 1000000007LL;
const int dir[4][2] = {1, 0, -1, 0, 0, -1, 0, 1};
const int INF = 0x3f3f3f3f;
bool vis[11111];
int S[111];
int n, sg[11111];
void cal_sg()
{
int i, j, k, tem;
sg[0] = 0;
for (i = 1; i <= 10000; ++i)
{
memset(vis, false, sizeof(vis));
for (j = 0; j < n; ++j)
{
if (i < S[j]) continue;
tem = i - S[j];
vis[sg[tem]] = true;
}
j = 0;
while (vis[j]) j++;
sg[i] = j;
}
}
int main()
{
while (scanf("%d", &n) != EOF && n)
{
int i, j, k;
for (i = 0; i < n; ++i)
scanf("%d", &S[i]);
cal_sg();
int m;
scanf("%d", &m);
for (i = 0; i < m; ++i)
{
int hi, a, ans = 0;
scanf("%d", &hi);
for (j = 0; j < hi; ++j)
{
scanf("%d", &a);
ans = ans ^ sg[a];
}
if (ans) printf("W");
else printf("L");
}
printf("\n");
}
return 0;
}