# hdu4277 dfs+set判重

http://acm.hdu.edu.cn/showproblem.php?pid=4277

Problem 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
/**
hdu4277  dfs+set判重

*/
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
typedef long long LL;

int n,ans,a[20];
set<LL> s;

void dfs(int cnt,int x,int y)
{
int z=ans-x-y;
if(cnt==n)
{
if(x<=y&&y<=z&&x+y>z)
{
s.insert(x*10000000+y);
}
return;
}
dfs(cnt+1,x+a[cnt],y);
dfs(cnt+1,x,y+a[cnt]);
dfs(cnt+1,x,y);
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
ans=0;
s.clear();
scanf("%d",&n);
for(int i=0; i<n; i++)
{
scanf("%d",&a[i]);
ans+=a[i];
}
dfs(0,0,0);
printf("%d\n",s.size());
}
return 0;
}


Problem 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