hdu 1518 深搜

时间:2024-10-21 14:34:02
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int len[],n,El;
int vi[];
int dfs(int k,int pos,int nowlen)
{
int i,j;
if(nowlen==El)
{
if(k==n)
return ;
else
nowlen=,pos=;
}
for(i=pos;i<n;i++)
{
if(!vi[i]&&nowlen+len[i]<=El)
{
vi[i]=;
if(dfs(k+,i+,nowlen+len[i]))
return ;
vi[i]=;
}
}
return ;
}
int main()
{
int t,i,j,Max,sum=;;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
Max=,sum=;
memset(vi,,sizeof(vi));
for(i=;i<n;i++)
{
scanf("%d",&len[i]);
if(len[i]>Max)
Max=len[i];
sum+=len[i];
}
El=sum/;
if(El*!=sum||Max>El)
{
printf("no\n");
continue;
}
if(dfs(,,))
printf("yes\n");
else
printf("no\n");
}
return ;
}