我的代码:
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, sum, t;
cin >> n;
t = pow(2, n);
int s[t + 10][t + 10];
for (int i = 1; i <= t; i++) {
for (int j = 1; j <= t; j++) {
if (i == j) {
s[i][j] = 1;
} else {
s[i][j] = 0;
}
}
}
int q[t + 10] = {0};
for (int i = 1; i < t; i++) {
int ans = 0;
cout << '<' << i << '>';
for (int i = 1; i <= t; i++) {
for (int j = 1; j <= t; j++) {
if (i == j) {
continue;
}
if (s[i][j] == 0 && q[i] == 0 && q[j] == 0) {
cout << i << '-' << j;
s[i][j] = 1;
q[i] = 1;
q[j] = 1;
ans++;
if (ans != (t / 2))
cout << ',';
if (ans == (t / 2))
cout << endl;
break;
}
}
}
for (int i = 1; i <= t; i++) {
q[i] = 0;
}
}
return 0;
}