当一个状态的后继状态有一个必败状态,我们可以通过移动到必败状态使得对手败。
当一个状态的后继状态全部为必胜状态,无论怎么移动对手都会取胜。
所以设d[x]表示先手拿到数字x的取胜情况,直接判断后继点的取胜情况即可。
#include <bits/stdc++.h> #include <unordered_map> using namespace std; typedef long long ll; typedef unsigned long long ull; #ifdef LOCAL #define debug(x) cout << "[" __FUNCTION__ ": " #x " = " << (x) << "]\n" #define TIME cout << "RuningTime: " << clock() << "ms\n", 0 #else #define TIME 0 #endif #define hash_ 1000000009 #define Continue(x) { x; continue; } #define Break(x) { x; break; } const int mod = 998244353; const int N = 1e6 + 10; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3f; #define gc p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++; inline int read(){ static char buf[1000000], *p1 = buf, *p2 = buf; register int x = false; register char ch = gc; register bool sgn = false; while (ch != '-' && (ch < '0' || ch > '9')) ch = gc; if (ch == '-') sgn = true, ch = gc; while (ch >= '0'&& ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = gc; return sgn ? -x : x; } ll fpow(ll a, int b, int mod) { ll res = 1; for (; b > 0; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } int d[N]; void dfs(int x) { if (d[x] != -1) return; if (x <= 9) return void(d[x] = 1); int mx = 0, mi = 11; int num = x; while (num) { int k = num % 10; if (k) mx = max(mx, k), mi = min(mi, k); num /= 10; } dfs(x - mi); dfs(x - mx); if (d[x - mi] && d[x - mx]) d[x] = 0; else d[x] = 1; } int main() { #ifdef LOCAL freopen("E:/input.txt", "r", stdin); #endif memset(d, -1, sizeof d); for (int i = 1; i <= 1000000; i++) dfs(i); int t; cin >> t; while (t--) { int n; scanf("%d", &n); printf("%s\n", d[n] ? "YES" : "NO"); } return TIME; }