大佬求救
  • 板块灌水区
  • 楼主25tcx
  • 当前回复1
  • 已保存回复1
  • 发布时间2023/11/25 13:36
  • 上次更新2023/11/25 15:33:33
查看原帖
大佬求救
1031089
25tcx楼主2023/11/25 13:36

代码:(题目:输出全排列)

#include <bits/stdc++.h>
using namespace std;
//string a[100005];
void dfs(int x,int n,vector<int>& box,vector<int>& visited){
	int c=sizeof(box);
	if(x==n+1){
		for(int i=1;i<c;i++){
			cout<<box[i]<<" ";
		}
		cout<<"\n";
		return;
	}
	for(int i=1;i<=n;i++){
		if(visited[i]==0){
			box[x]=i;
			visited[i]=1;
			dfs(x+1,n,box,visited);
			visited[i]=0;
		}
	}
}
int main()
{
//	freopen("name1.in","r",stdin);
//	freopen("name1.out","w",stdout);
	int n;
	vector<int> box;
	vector<int> fhj;
	cin>>n;
	box.resize(n+1,0);
	fhj.resize(n+1,0);
	dfs(1,n,box,fhj);
	return 0;
}

输出:(样例输入:3)

1 2 3 -2061570609 28369 12987128 12976320 -1038094967 201354960 0 -1
1 3 2 -2061570609 28369 12987128 12976320 -1038094967 201354960 0 -1
2 1 3 -2061570609 28369 12987128 12976320 -1038094967 201354960 0 -1
2 3 1 -2061570609 28369 12987128 12976320 -1038094967 201354960 0 -1
3 1 2 -2061570609 28369 12987128 12976320 -1038094967 201354960 0 -1
3 2 1 -2061570609 28369 12987128 12976320 -1038094967 201354960 0 -1

--------------------------------
Process exited after 0.9945 seconds with return value 0
请按任意键继续. . .

求救T-T

2023/11/25 13:36
加载中...