33,009
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <algorithm>
using namespace std;
void main()
{
int a[3][4] = {1,2,3,4,5,6,7,8,9,10,11,12};
int row[12], count = 0;
for(int r = 0; r < 3; r++)
for(int i = 0; i < 4; i++)
row[r*4+i] = r;
do {
int i, b[3];
for(i = b[0] = b[1] = b[2] = 0; i < 12; i++)
printf("%2d ", a[ row[i] ][ b[row[i]]++ ] );
printf("\n");
count++;
}while( next_permutation(row, row + 12) );
printf("count=%d\n",count);
}