Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3581 Accepted Submission(s): 1196
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.
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)
int aa[maxn]; set<int> kiss; int n; void dfs(int a,int b,int c,int d) { if(d==n) { if(a*b*c*d==0) return; if(a+b>c&&a<=b&&b<=c) { kiss.insert(a*1000010000+b*10000+c); } return; } dfs(a+aa[d],b,c,d+1); dfs(a,b+aa[d],c,d+1); dfs(a,b,c+aa[d],d+1); } int main() { int t; RD(t); while(t--) { kiss.clear(); RD(n); REP(i,n) { RD(aa[i]); } dfs(0,0,0,0); cout<<kiss.size()<<endl; } }