dfs 第4题

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

共 1 条回复

CPP 刷题王

a[0]=1你确定是真心的? dfs(1);前