组合的输出
https://www.luogu.com.cn/problem/P1157
#include<bits/stdc++.h>
using namespace std;
int n,r;
bool v[50];
int f[50];
//now 用哪个数填 l填第几个空
void dfs(int now,int pos){
if(pos==r+1){//r个空填满
for(int i=1;i<=r;i++){
printf(“%3d”,f[i]);
}
printf(“\n”);
return;
}
for(int i=now;i<=n;i++){//从now下一个数填 避免重复 if(!v[i]){//本轮 此数未填过 v[i]=true;f[pos]=i;dfs(i+1,pos+1);v[i]=false;}
}
}
int main(){
cin>>n>>r;
dfs(1,1);
return 0;
}