http://acm.hdu.edu.cn/showproblem.php?pid=1518
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int tt,num[25],flag[25],aver,f;
void dfs(int length,int count,int k)
{
if(f)
{
return ;
}
if(length==aver)
{
count++;
if(count==4)
{
f=1;
return ;
}
k=0;
length=0;
}
for(int i=k;i<tt;i++)
{
if(!flag[i] && length+num[i]<=aver)
{
flag[i]=1;
dfs(length+num[i],count,i);
flag[i]=0;
}
}
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d",&tt);
int sum=0,max=0;
for(int i=0;i<tt;i++)
{
scanf("%d",&num[i]);
sum+=num[i];
if(num[i]>max)
{
max=num[i];
}
}
if(sum%4!=0||max>(sum/4))
{
printf("no\n");
continue;
}
aver=sum/4;
memset(flag,0,sizeof(flag));
f=0;
dfs(0,0,0);
if(f==1)
{
printf("yes\n");
}else{
printf("no\n");
}
}
return 0;
}