一开始没用记忆化搜索啊!T到没朋友啊!
后来用了记忆化搜索啊!还是T到没朋友啊!
再后来看了网上的标程啊!尼玛居然连sort都没sort就能过啊!
我当这能省时间啊!结果我特么就WA了啊!WA到没朋友啊!
结果网上那程序还是特么能过啊!我真的脸黑么啊啊啊啊啊!!!!
好了总结一下:
1、还是要sort的,也要用记忆化搜索。
2、这题居然卡我的memset的次数?!总算知道没朋友的原因了。
3、SG函数的应用。
标程满天飞的年代,我只是纪念下而已。
//HDU-1536.cpp
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <cctype>
#include <algorithm>
#include <iostream>
#include <string>
#include <stack>
#include <map>
#include <set>
#include <queue>
#include <utility>
#include <vector>
#include <bitset>
#include <functional>
using namespace std;
//const double pai = acos(-1.0);
const double pai = 3.14159265358979323846;
const int INF = 0x3f3f3f3f;
typedef long long love_live;
int oparr[117], sg[10017], kk;
int getsg(int x){
if(sg[x] != -1){
return sg[x];
}
int mex[117] = {0}, i, j, k;
for(i = 0; i < kk; i++){
int tmp = x - oparr[i];
if(tmp < 0){
break;
}
getsg(tmp);
mex[sg[tmp]] = 1;
}
int ans = 0;
for(i = 0; i <= 100; ++i){
if(!mex[i]){
ans = i;
break;
}
}
return sg[x] = ans;
}
int main(int argc, char const *argv[]) {
#ifndef ONLINE_JUDGE
// freopen("output", "w", stdout);
freopen("input", "r", stdin);
#endif
int n, m, i, j, k, l, ans;
while(scanf("%d", &kk) != EOF){
if(kk == 0){
break;
}
memset(oparr, 0, sizeof(oparr));
for(i = 0; i < kk; ++i){
scanf("%d", &oparr[i]);
}
sort(oparr, oparr + kk);
scanf("%d", &m);
memset(sg, -1, sizeof(sg));
sg[0] = 0;
while(m--){
scanf("%d", &l);
ans = 0;
for(i = 0; i < l; ++i){
scanf("%d", &k);
ans ^= getsg(k);
}
if(ans != 0){
printf("W");
}
else{
printf("L");
}
}
printf("\n");
}
return 0;
}