You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.1 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include <bits/stdc++.h>
using namespace std;
const int N = 110;
const int M = 10010;
int n, k;
int a[N]; // 一共几种取法比如一次取2个或5个。
int f[M]; // SG函数的值
int res;
int sg(int x) {
if (~f[x]) return f[x]; // 记忆化搜索
unordered_set<int> S;
for (int i = 0; i < k; i++)
if (x >= a[i]) S.insert(sg(x - a[i])); // x-s[i]:x的可行路径中终点有哪几个; sg(x-s[i]):这个终点它的sg值
for (int i = 0;; i++)
if (!S.count(i)) return f[x] = i;
}
int main() {
memset(f, -1, sizeof f); // 初始化数组值为-1
cin >> k; // 表示数字集合S中数字的个数
for (int i = 0; i < k; i++) cin >> a[i];
cin >> n; // 一共几堆
// n堆石子每堆石子都取SG值然后异或在一起
for (int i = 0; i < n; i++) {
int x;
cin >> x; // 每堆里多少个
res ^= sg(x);
}
if (res)
puts("Yes"); // 如果不是零,必胜
else
puts("No"); // 如果是零,必败
return 0;
}