1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| #include <iostream> #include <algorithm> #include <functional> #include <cstring> using namespace std; bool vis[10010]; int avg, n, st[10010]; bool dfs(int len, int pos, int cnt) { if (cnt == 3) return true; for (int i = pos; i < n; i++) { if (vis[i] || len + st[i] > avg) continue; vis[i] = true; if (len + st[i] == avg && dfs(0, 0, cnt + 1)) return true; else if (len + st[i] != avg && dfs(len + st[i], i + 1, cnt)) return true; vis[i] = false; } return false; } int main() { int T; cin >> T; while (T--) { avg = 0; cin >> n; for (int i = 0; i < n; i++) cin >> st[i], avg += st[i]; if (avg % 4 != 0) { cout << "No" << endl; continue; } avg /= 4; memset(vis, false, sizeof(vis)); sort(st, st + n, greater<int>()); cout << (st[0] > avg || !dfs(0, 0, 0) ? "No" : "Yes ") << endl; } return 0; }
|