天梯赛-正方形游戏
#include
#include
#include
#include
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());
cout << (st[0] > avg || !dfs(0, 0, 0) ? "No" : "Yes ") << endl;
}
return 0;
}