Files
python/TangDou/AcWing/GameTheory/893.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

42 lines
1.1 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}