提交时间:2023-08-25 19:25:37

运行 ID: 100425

#include <iostream> using namespace std; int n,m; bool used[25]; int a[25]; void dfs(int deep,int now){ if (deep==m){ for (int i = 1;i<=m;i++) cout << a[i]; cout << "\n"; } for (int i = now+1;i<=n;i++){ if (!used[i]){ used[i]=true; a[deep+1]=i; dfs(deep+1,i); used[i]=false; } } } int main(){ cin >> n >> m; dfs(0,0); }