0pts求助
查看原帖
0pts求助
565378
Orange1015楼主2022/7/2 15:32
#include<bits/stdc++.h>
using namespace std;
int a[15],n;
bool v[15];
void dfs(int x){
	if(x==n+1){
		for(int i=1;i<=n;i++) cout << setw(5) << a[i] << " ";
		cout << '\n';
		return;
	}
	for(int i=1;i<=n;i++){
		if(!v[i]){
			a[x] = i;
			v[i] = true;
			dfs(x+1);
			v[i]=0;
		}
	}
	return;
}
int main(){
	std::ios::sync_with_stdio(false);
	cin >> n;
	dfs(1);
	return 0;
}

可以过样例,但是0分。

2022/7/2 15:32
加载中...