#include #include #include #include using namespace std; bool have = false; set> visited; int A, B, C; // 三个容器的容量 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); // 六种倒水操作 // 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); // 假设初始是 A 装满 if (have) cout << "YES" << endl; else cout << "NO" << endl; return 0; }