20分求助,各位大佬,我是个FW
查看原帖
20分求助,各位大佬,我是个FW
723596
chenkuntao楼主2023/8/21 20:47
#include <bits/stdc++.h>
using namespace std;
int n,r;
int a[100];
bool vis[100];
void dfs(int x){
	if(x>r){
		for(int i=1;i<=r;i++){
			cout<<setw(3)<<a[i]; 
		}
		cout<<endl;
		return;
	}
	for(int i=1;i<=n;i++){
		if(vis[i]==0){
			a[x]=i;
			vis[i]=1;
			dfs(x+1);
			vis[i]=0;
		}
	}
	
}
int main(){
	cin>>n>>r;
	dfs(1);
	return 0;
} 
2023/8/21 20:47
加载中...