文章

105

粉丝

69

获赞

116

访问

36.2k

头像
全排列(dfs搜索) 题解:

#include<bits/stdc++.h>
using namespace std;

string str, res; 
int n;
bool st[10];

void dfs(int u)
{
	if(u >= n)
	{
		cout << res << endl;
		return ;
	}
	
	for(int i = 0; i < n; i ++)
	{
		if(!st[i])
		{
			res.push_back(str[i]);
			st[i] = true;
			dfs(u + 1);
			res.pop_back();
			st[i] = false; 
		}
	}
}

int main()
{
	cin >> str;
	
	n = str.size();
	dfs(0);
	
	return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发