@Chilling
2017-01-16T16:16:11.000000Z
字数 1552
阅读 964
搜索
Description
Like everyone, cows enjoy variety. Their current fancy is new shapes for pastures. The old rectangular shapes are out of favor; new geometries are the favorite.
I. M. Hei, the lead cow pasture architect, is in charge of creating a triangular pasture surrounded by nice white fence rails. She is supplied with N fence segments and must arrange them into a triangular pasture. Ms. Hei must use all the rails to create three sides of non-zero length. Calculating the number of different kinds of pastures, she can build that enclosed with all fence segments.
Two pastures look different if at least one side of both pastures has different lengths, and each pasture should not be degeneration.
Input
The first line is an integer T(T<=15) indicating the number of test cases.
The first line of each test case contains an integer N. (1 <= N <= 15)
The next line contains N integers li indicating the length of each fence segment. (1 <= li <= 10000)
Output
For each test case, output one integer indicating the number of different pastures.
Sample Input
1
3
2 3 4
Sample Output
1
#include<stdio.h>
#include<string.h>
#include<set>
using namespace std;
int flag,n,a[22];
set< pair<int,int> >s;
void dfs(int l1,int l2,int l3,int count)//分别表示三条边和已经使用了的边数
{
if(count==n)
{
if(l1<=l2&&l2<=l3&&l1+l2>l3)//令短边是l1和l2,之后装入两个短边的值 ,保证他们的顺序,能保证不重复
{
s.insert(pair<int,int>(l1,l2)); //set里不会有重复的数据,装入两个值,第三边也是确定的!
}
return;
}
dfs(l1+a[count],l2,l3,count+1);
dfs(l1,l2+a[count],l3,count+1);
dfs(l1,l2,l3+a[count],count+1);
}
int main()
{
int t,i;
scanf("%d",&t);
while(t--)
{
s.clear();//记住要清空啊!!
memset(a,0,sizeof(a));
flag=1;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
if(n<=2)
flag=0;
else
dfs(0,0,0,0);
if(flag==0)
printf("0\n");
else
printf("%d\n",s.size());
}
return 0;
}