#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int a[250],len,r[205],n,sum;
int dfs(int p,int q,int z)
{
if(p==3)
return 1;
int j;
for(j=q;j>=0;j--){
if(!r[j]){
r[j]=1;
if(z+a[j]<len){
if(dfs(p,j-1,z+a[j]))
return 1;
}else if(z+a[j]==len){
if(dfs(p+1,n-1,0))
return 1;
}
r[j]=0;
}
}
return 0;
}
int main(){
int i,k,m;
scanf("%d",&m);
while(m--){
sum=0;
scanf("%d",&n);
for(i=0;i<n;sum+=a[i],i++)
scanf("%d",&a[i]);
len=sum/4;
memset(r,0,sizeof(r));
sort(a,a+n);
if(len*4!=sum || len<a[n-1]){
printf("no\n");
continue;
}
if(dfs(0,n-1,0))
printf("yes\n");
else
printf("no\n");
}
return 0;
}
POJ2362:Square
最新推荐文章于 2024-08-21 11:40:52 发布