#include <bits/stdc++.h> using namespace std; int n,r,a[25]; bool vis[25]; void dfs (int dep) { for (int i=a[dep-1]+1;i<=n;i++) { if (!vis[i]) { a[dep]=i; if (dep==r) { for (int j=1;j<=r;j++) cout<<setw(3)<<a[j]; cout<<endl; } else dfs(dep+1); vis[i]=0; } } } int main() { cin>>n>>r; dfs(1); return 0; }
标签:输出,组合,25,int,dfs,dep From: https://www.cnblogs.com/jck211303/p/17572234.html