题目描述
在2行5列的格子中填入1到10的数字。
要求:相邻的格子中的数,右边的大于左边的,下边的大于上边的。
如下图所示的2种,就是合格的填法。
请你计算一共有多少种可能的方案。
输出
请输出该整数,不要输出任何多余的内容
#include <iostream>
#include <algorithm>
using namespace std;
int a[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int cnt;
int main(){
do{
for (int i = 0; i < 5; i ++ ){
if ((a[i] > a[i + 1] && i + 1 < 5) || (a[i + 5] > a[i + 6] && i + 6 < 10) || a[i] > a[i + 5]){
cnt ++;
break;
}
}
}
while (next_permutation(a, a + 10));
cout << 3628800 - cnt << endl;
return 0;
}