dfs实现全排列

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
int bok[100];
int path[100];
void dfs(int step)
{
	if(step==4)
	{
		for(int i=1;i<=step-1;i++) cout<<path[i];
		cout<<endl;
		return ;
	}
	for(int i=1;i<=3;i++)
	{
		if(!bok[i])
		{
			path[step] = i;
			bok[i] = 1;
			dfs(step+1);
			bok[i] = 0;
		}
	}
}
int main()
{
	int a[]={0,1,2,3,4};
	dfs(1);
}


posted @ 2020-07-04 09:57  特立独行的猪猪  阅读(127)  评论(0编辑  收藏  举报