2015
05-23

# USACO ORZ

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.

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)

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)

1
3
2 3 4

1

USACO ORZ

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
#include<vector>
#include<string>
#define LL long long
#define N 25
using namespace std;
int num[N];
int n,summ,xj,xk;
int Case;
struct node
{
int x,y,z;
bool operator < (const struct node &a) const
{
return (x!=a.x)?(x<a.x):(y!=a.y?(y<a.y):(z<a.z));
}
}temp,ans;
set<struct node> hashx;
void dfs(int);
int main()
{
scanf("%d",&Case);
for(int c=0;c<Case;c++)
{
summ=0;hashx.clear();
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&num[i]);
summ+=num[i];
}
temp.x=num[1];temp.y=0;
if(n<3)
{
printf("%d\n",0);
continue;
}
dfs(2);
printf("%d\n",hashx.size());
}
return 0;
}
void dfs(int x)
{
if(x>n)
{
xj=temp.x;
xk=temp.y;
if(((xj+xk)>(summ-xj-xk))&&(summ-xk>xk)&&(summ-xj>xj))
{
ans.x=max(xj,max(summ-xj-xk,xk));
ans.z=min(xj,min(summ-xj-xk,xk));
if(xj!=ans.x&&xj!=ans.z) ans.y=xj;
else if(xk!=ans.x&&xk!=ans.z) ans.y=xk;
else ans.y=summ-ans.x-ans.z;
hashx.insert(ans);
}
return;
}
dfs(x+1);
temp.x+=num[x];
dfs(x+1);
temp.x-=num[x];
temp.y+=num[x];
dfs(x+1);
temp.y-=num[x];
}