Description
Input
Output
Sample Input
2 4
Sample Output
12
Hint
#include <stdio.h>
#include <conio.h>
#include <stdlib.h> //system(); 这个指令需要用到此头文件
#include <ctype.h> //toupper要用到
#include <malloc.h> //在内存管理时用到的头文件
#include <string.h> //字符串的头文件
#include <math.h> //数学运算
int m = 0, n = 0, c[1000] = { NULL }, position = 0, count_can = 0;
bool jump(int x[])
{
int temp1[1000] = { NULL }, temp2[1000] = { NULL };
for (int i = 0; x[i] != NULL; i++)
{
if (x[i] == 1)
return(true);
temp1[i] = x[i];
}
int l = 1, s = 0;
do{
s = 0;
if (l == 1)
{
for (int i = 0; temp1[i] != NULL; i++)
{
for (int j = i + 1; temp1[j] != NULL; j++)
{
if (fabs(temp1[i] - temp1[j]) == 1)
{
return(true);
}
if (temp1[i] - temp1[j] != 0)
{
temp2[s] = (int)fabs(temp1[i] - temp1[j]);
s++;
}
}
temp1[i] = 0;
}
l = 2;
}
else
{
for (int i = 0; temp2[i] != NULL; i++)
{
for (int j = i + 1; temp2[j] != NULL; j++)
{
if (fabs(temp2[i] - temp2[j]) == 1)
{
return(true);
}
if (temp2[i] - temp2[j] != 0)
{
temp1[s] = (int)fabs(temp2[i] - temp2[j]);
s++;
}
}
temp2[i] = 0;
}
l = 1;
}
} while (s != 0);
return(false);
}
void card(int depth)
{
if (depth == m)
{
c[m] = n;
if (jump(c) == true)
{
count_can++;
}
return;
}
else
{
for (int i = 1; i <= n; i++)
{
c[depth] = i;
depth++;
card(depth);
depth--;
}
return;
}
}
void main()
{
scanf("%d%d", &m, &n);
card(0);
printf("%d\n", count_can);
}ACM之跳骚---ShinePans,布布扣,bubuko.com
原文:http://blog.csdn.net/panshang1994/article/details/27838509