dfs 第一题

ykj12 2022-07-17 10:03:59 1
#include<bits/stdc++.h>
using namespace std;
int n,r;
const int N=20;
int a[N],vis[N];
void dfs(int u){
	if(u==r+1){
		for(int i=1;i<=r;i++){
			printf("%d ",a[i]);
		}
		puts("");
		return;
	}
	for(int i=1;i<=n;i++){
		if(vis[i]==0){
			vis[i]=1;
			a[u]=i;
			dfs(u+1);
			vis[i]=0;
		}
	}
}
int main(){
	freopen("a.in","r",stdin);
	freopen("a.out","w",stdout);
	scanf("%d %d",&n,&r);
	a[0]=1;
	dfs(1);
	return 0;
}
{{ vote && vote.total.up }}