hdoj1536 为什么算法超时了

代码如下:

#include
#include
#include
#include
using namespace std;

#define N 10010

int s[110];
int h[N];
int k, l, m;
int DFS(int n)
{
sets1;
if (h[n] != -1)return h[n];
if (n - s[0] < 0)return h[n] = 0;
for (int i = 0; i < k&&n - s[i] >= 0; i++)s1.insert(DFS(n - s[i]));
int res = 0;
while (s1.count(res))res++;
return h[n] = res;
}

int main()
{

while (scanf("%d", &k) && k)
{

    int num;
    memset(h, -1, sizeof(h));
    memset(s, 0, sizeof(s));
    h[0] = 0;
    for (int i = 0; i < k; i++)
        scanf("%d", &s[i]);
    sort(s, s + k);
    scanf("%d", &m);
    while (m--)
    {
        int ans = 0;
        scanf("%d", &l);
        for (int i = 0; i < l; i++)
        {
            scanf("%d", &num);
            ans ^= DFS(num);
        }
        if (ans == 0)printf("L");
        else printf("W");

    }
    printf("\n");
}
return 0;

}

http://blog.csdn.net/xiamiwage/article/details/7994049