Files
python/GESP/Mkx/2025032904.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

47 lines
680 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}