This commit is contained in:
e2hang
2025-09-02 08:59:59 +08:00
parent 0d058fc8ac
commit 6839d2ea13

View File

@@ -0,0 +1,63 @@
#include <iostream>
#include <vector>
#include <set>
#include <bits/stdc++.h>
using namespace std;
bool have = false;
set<tuple<int,int,int>> visited;
int A, B, C; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void dfs(int a, int b, int c, int target) {
if (a == target || b == target || c == target) {
have = true;
return;
}
auto state = make_tuple(a, b, c);
if (visited.find(state) != visited.end()) return;
visited.insert(state);
// <20><><EFBFBD>ֵ<EFBFBD>ˮ<EFBFBD><CBAE><EFBFBD><EFBFBD>
// a -> b
{
int pour = min(a, B - b);
dfs(a - pour, b + pour, c, target);
}
// a -> c
{
int pour = min(a, C - c);
dfs(a - pour, b, c + pour, target);
}
// b -> a
{
int pour = min(b, A - a);
dfs(a + pour, b - pour, c, target);
}
// b -> c
{
int pour = min(b, C - c);
dfs(a, b - pour, c + pour, target);
}
// c -> a
{
int pour = min(c, A - a);
dfs(a + pour, b, c - pour, target);
}
// c -> b
{
int pour = min(c, B - b);
dfs(a, b + pour, c - pour, target);
}
}
int main() {
int target;
cin >> A >> B >> C >> target;
dfs(A, 0, 0, target); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC> A װ<><D7B0>
if (have) cout << "YES" << endl;
else cout << "NO" << endl;
return 0;
}