//搭积木 768 #include using namespace std; int row = 4, col; int seq[5][8]; //下标从1开始 int tmp[11]; int cnt = 0; bool used[10]; void change() { //将一维数组转换成二维数组 int cur = 1; for (int i = 1; i <= row; ++i) { for (int j = 1; j <= i; ++j) { seq[i][j] = tmp[cur++]; } } } bool judge() { //判断二维数组是否符合条件 for (int i = 1; i <= row - 1; ++i) { for (int j = 1; j <= i; ++j) { if (seq[i][j] > seq[i + 1][j] || seq[i][j] > seq[i + 1][j + 1]) return false; } } return true; } int ans = 0; void dfs(int idx) { //idx:当前要操作的下标(从1开始) if (idx == 11) { change(); if (judge()) { cnt++; return; } return; } for (int i = 0; i <= 9; ++i) { if (!used[i]) { tmp[idx] = i; used[i] = true; dfs(idx + 1); used[i] = false; } } } int main() { memset(used, false, sizeof(used)); dfs(1); cout << cnt << endl; return 0; }