/*
    ID:chenjiong
    PROG:subset
    LANG:C++
*/

#include <stdio.h>
#include <string.h>
#include <algorithm>

using namespace std;

const int MAXN = 40;

int N;
int set[MAXN];
int use[MAXN];
int sum_a,sum_b;
int cnt_a,cnt_b;
int cnt;
int sum;

void init()
{
    int i;
    scanf("%d",&N);
    for ( i = 0; i < N; i++)
    {
        set[i] = i + 1;
        sum += set[i];
    }
}

void division(int size)
{
    memset(use,0,sizeof(use));
    cnt_a = size;
    cnt_b = N - size;
    
    int i;
    for ( i = N - cnt_a; i < N; i++)
        use[i] = 1;
    
    do 
    {
        sum_a = sum_b = 0;
        for ( i = 0; i < N; i++)
        {
            switch( use[i] )
            {
                case 0 : sum_b += set[i]; break;
                case 1 : sum_a += set[i]; break;
            }
        }
        if ( sum_a == sum_b && sum_a != 0 )
            cnt++;
    } while ( next_permutation(use,use + N) );

}

int main()
{
//    freopen("subset.in","r",stdin);
//    freopen("subset.out","w",stdout);

    int x,j;
    init();

    if ( N * ( N + 1 ) % 4 != 0 )
    {
        printf("0\n");
        return 0;
    }

    if ( N % 2 == 1 )
    {
        for ( x = 1; x <= N / 2; x++)
            division(x);
    }
    else
    {
        for ( x = 1; x < N / 2; x++)
            division(x);
        int tmp = cnt;
        cnt = 0;
        division(N / 2);
        cnt /= 2;
        cnt = tmp + cnt;
    }
    printf("%d\n",cnt);

    return 0;
}

 

posted on 2012-11-02 21:23  Sinker  阅读(123)  评论(0编辑  收藏  举报