Files
python/GESP/Mkx/2025032904.cpp

47 lines
680 B
C++
Raw Normal View History

2025-08-30 18:35:01 +08:00
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int st[N];
vector<int> vec;
int n, m; // m 个盒子,n个小球,编号为1~ n
/*
测试用例:
4 2
答案:
1 2
1 3
1 4
2 3
2 4
3 4
*/
void dfs(int u) {
if (u > m) {
for (int i = 0; i < vec.size(); i++)
cout << vec[i] << " ";
cout << endl;
return;
}
for (int i = 1; i <= n; i++) {
if (vec.size() >= 1 && i <= vec[vec.size() - 1])
continue;
if (!st[i]) {
st[i] = 1;
vec.push_back(i);
dfs(u + 1);
vec.pop_back();
st[i] = 0;
}
}
}
int main() {
cin >> n >> m;
dfs(1);
return 0;
}