hdu-5937-equation

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
using namespace std;

int start, end;
int num[10];
int m[10][10];
int aws, cnt;
int search(int);
int main()
{
    int t, i, j, k;
    //t = 1;
    scanf("%d", &t);
    for (i = 0; i < t; i++)
    {

        aws = 0;
        for (j = 1; j < 10; j++)
            scanf("%d", num + j);
        for (j = 1; j < 10; j++)
        {
            for (k = 1; k < 10; k++)
            {
                m[j][k] = m[k][j] = num[j] && num[k] && (j + k < 10) && (j != k || num[j] >= 2);
            }
        }
        search(0);
        //end = clock();
        printf("Case #%d: %dn", i + 1, aws);

    }
    return 0;
}

int search(int n)
{
    int j, k, flag;
    for (j = 1; j < 10; j++)
    {
        if (!num[j])
            continue;
        for (k = 1; k <=j ; k++)
        {
            if (m[j][k] && num[j] && num[k] && num[j + k] && (j != k || num[j] >= 2))
            {
                num[j]--;
                num[k]--;
                num[j + k]--;
                m[j][k] = 0;
                cnt++;
                /*sprintf(s +temp, "%d %dn", j, k);*/
                search(n + 1);
                num[j]++;
                num[k]++;
                num[j + k]++;
                m[j][k] = 1;
                cnt--;
            }
        }
    }

    if (cnt > aws)
        aws = cnt;
    //if (cnt == 6)
    //    fputs("**********************************************", p);
    //sprintf(s + strlen(s), "%dn", cnt);
    //fputs(s, p);
    ////printf("n");
    return 1;
}