###### poj 2362
#include<iostream>
#include<iterator>
#include<algorithm>
using namespace std;
const int maxn=22;
int n;
int visited[maxn];
int dfs(int stick[],int curlen,int s,int deslen,int num)
{
if(num==4)
return 1;
for(int i=s;i<n;i++)
{
if(!visited[i])
{
visited[i]=1;
if(curlen+stick[i]==deslen)
{
if(dfs(stick,0,0,deslen,num+1))
return 1;

}
else if(curlen+stick[i]<deslen)
{
if(dfs(stick,curlen+stick[i],i,deslen,num))
return 1;
}
visited[i]=0;   //这里就是回朔要注意
}

}
return 0;
}
int cmp(int a,int b)
{
return a>b;
}
int main()
{
int nCase;
int stick[22];
cin>>nCase;
while(nCase--)
{
cin>>n;
int sum=0;
for(int i=0;i<n;i++)
{
cin>>stick[i];
sum+=stick[i];
}
memset(visited,0,sizeof(visited));
sort(stick,stick+n,cmp);
/*
思路大致是这样，首先判断棍子是否能被4正除，若能，求出棍子的长度，然后在里面找起组合，
若能组成4条这样的那么就行了
*/
//   copy(stick,stick+n,ostream_iterator<int>(cout,","));
if(sum%4!=0)
cout<<"no"<<endl;
else
{
if(dfs(stick,0,0,sum/4,1))
//这里stick表示棍子，curlen表示当前长度，deslen表示目标长度，num表示当前以求出的数目，若==4，则行
cout<<"yes"<<endl;
else
cout<<"no"<<endl;
}
}
system("pause");

}

#### POJ2362-Square

2011-07-31 10:26:06

#### POJ 2362 Square(DFS回溯构造)

2014-05-29 22:24:47

#### TOJ 1398 POJ 2362 Square DFS

2012-01-12 22:28:45

#### HDU1518 & POJ2362 & ZOJ1909 Square

2014-04-17 11:32:16

#### POJ2362：Square(DFS)

2013-11-30 21:52:41

#### poj2362Square

2015-08-26 14:56:02

#### POJ 2362

2016-02-28 12:43:54

#### PIM协议翻译及深入理解分析（rfc2362第二章）

2014-07-30 16:50:45

#### 【搜索】bzoj1086: [SCOI2005]王室联邦

2017-10-30 10:05:45

#### poj 2362 dfs

2016-08-06 22:53:35

poj 2362