在N行N列的数阵中, 数K(1〈=K〈=N)在每行和每列中出现且仅出现一次,这样的数阵叫N阶拉丁方阵。例如下图就是一个五阶拉丁方阵。
编一程序,从键盘输入N值后,打印出所有不同的N阶拉丁方阵,并统计个数。
1 2 3 4 5
2 3 4 5 1
3 4 5 1 2
4 5 1 2 3
5 1 2 3 4
#include <iostream>
#include <stdio.h>
using namespace std;
void printM(int M)
{
//只有一个数的时候输出1
if (M == 1)
{
printf("1");
}
//生成在拉丁方阵中出现的数据序列
int *elementArray = new int[M];
for (int i =