USACO ORZ
time limit per test 1.5 second memory limit per test 256 megabytes
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.

传送门:HDU4277

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
2
3
1
3
2 3 4

Sample Output

1
1

题解

一看就是个O(3^15)的dfs 但细节还有很多要推敲的 比如剪枝 比如有序性 还有不要像我一样在dfs中还排序写复杂TLE了= =
## AC code:(不包含输入类)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import java.io.*;  
import java.util.*;
public class Main {
static int[]shu;
static int sum;
static ArrayList<Integer>list=new ArrayList<Integer>();
static HashSet<Node>set=new HashSet<Node>();
//static HashSet<Long>set=new HashSet<Long>();
public static void main(String[] args) {
FastScanner sc=new FastScanner();
PrintWriter pw=new PrintWriter(System.out);
int t=sc.nextInt();
while(sc.hasNext()){
int n=sc.nextInt();
shu=new int[n];
sum=0;
for(int i=0;i<n;i++){
shu[i]=sc.nextInt();
sum+=shu[i];
}
set.clear();
dfs(0,0,0,n);
pw.println(set.size());
pw.flush();
}
}
static void dfs(int index,int a,int b,int n){
if(a>sum/2||b>sum/2)return; //剪枝
if(index==n){
list.clear();
if(a!=0&&b!=0){
int c=sum-a-b;
if(a<=b&&b<=c&&a+b>c){ //有序性
set.add(new Node(a,b,c));
//set.add(1000000L*a+b);
}
}
return;
}
dfs(index+1,a+shu[index],b,n);
dfs(index+1,a,b+shu[index],n);
dfs(index+1,a,b,n);
}
}
class Node implements Comparable<Node>{
int a;
int b;
int c;
Node(int a,int b,int c){
this.a=a;
this.b=b;
this.c=c;
}
@Override
public int compareTo(Node o) {
if(this.a<o.a)return -1;
if(this.a>o.a)return 1;
if(this.b<o.b)return -1;
if(this.b>o.b)return 1;
if(this.c<o.c)return -1;
if(this.c>o.c)return 1;
return 0;
}
public int hashCode(){
return a;
}
public boolean equals(Object obj){
if (obj instanceof Node){
Node node = (Node)obj;
if(this.a!=node.a)return false;
if(this.b!=node.b)return false;
if(this.c!=node.c)return false;
return true;
}
return false;
}
}