'commit'
This commit is contained in:
42
TangDou/AcWing/GameTheory/893.cpp
Normal file
42
TangDou/AcWing/GameTheory/893.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user