#include<stdio.h>
#include<malloc.h>
#include<math.h>
int len,count;
void solution(int n,int line[],int positive,int negative)
{
int i,nextLine[20];
/*for debug*///for(i=0;i
//count it!
for(i=0;i<n;i++) line[i]==1?positive++:negative++;
//break it when ...
if(positive>(len*(len+1)/4)||negative>(len*(len+1)/4)) return;
//it's over and return
if(n==len)
{
count++;
/*for debug*///printf("p=%d n=%d count=%d\n",positive,negative,count);
return;
}
else
{
nextLine[0]=-1;
for(i=0;i<n;i++) nextLine[i+1]=nextLine[i]*line[i];
solution(n+1,nextLine,positive,negative);
nextLine[0]=1;
for(i=0;i<n;i++) nextLine[i+1]=nextLine[i]*line[i];
solution(n+1,nextLine,positive,negative);
}
}
void countEquel()
{
int sign;
if((len*(len+1)/2)%2!=0) return;
else
{
sign=-1;
solution(1,&sign,0,0);
sign=1;
solution(1,&sign,0,0);
}
}
void main()
{
typedef struct trst
{
int result;
struct trst *next;
}rst;
rst *head,*p;
head=p=(rst*)malloc(sizeof(rst));
p->next=NULL;
while(1)
{
scanf("%d",&len);
if(len)
{
p->next=(rst*)malloc(sizeof(rst));
p=p->next;
p->next=NULL;
}
else break;
//count...
count=0;
countEquel();
p->result=count;
}
p=head->next;
while(p)
{
printf("%d\n",p->result);
p=p->next;
}
}
/*
void main()
{
len=20;
count=0;
countEquel();
printf("%d\n",count);
}
*/
|