将1、2、3、4、5和6填入下表中,要使得每一列右边的数字比左边的大,每一行下面的数字比上面的大,问一共有几种填写方法?
#include <stdio.h>
int count;
int jud1(int *s)
{
int i, l;
for (l = 1; l < 4; l++)
{
for (i = l + 1; i < 5; ++i)
{
if(s[l] == s[i])
{
return 0;
}
}
}
return 1;
}
void print(int *u)
{
int k;
for (k = 0; k < 6; k++)
{
if(0 == k % 3)
{
printf("\n %d", u[k]);
}
else
{
printf("%d", u[k]);
}
}
}
int main()
{
static int a[] = {1, 2, 3, 4, 5, 6};
printf("The possible table satisfied above conditions are: \n");
for (a[1] = a[0] + 1; a[1] <= 5; ++a[1])
{
for (a[2] = a[1] + 1; a[2] <= 5; ++a[2])
{
for (a[3] = a[0] + 1; a[3] <= 5; ++a[3])
{
for (a[4] = a[1] > a[3] ? a[1] + 1 : a[3] + 1; a[4] <= 5; ++a[4])
{
if(jud1(a))
{
print(a);
}
}
}
}
}
printf("\n");
return 0;
}