当前位置:网站首页>1.3.1 Full Permutation Problem
1.3.1 Full Permutation Problem
2022-07-27 08:43:00 【Madness makes freedom】
1.3.1 The total permutation problem
Description
Output natural numbers 111 To nnn All the non repetitive permutations , namely nnn The whole arrangement , It is required that no duplicate number is allowed in any number sequence generated .
Input
The first line is an integer nnn
Output
from 111 to nnn A sequence of all the numbers that do not repeat , One sequence per line .
Each number is separated by a space
Sample Input 1
3
Sample Output 1
1 2 3 1 3 2 2 1 3 2 3 1 3 1 2 3 2 1
Hint
1≤n≤91 \le n \le 91≤n≤9
#include<stdio.h>//uncle-lu
/*
Perform a depth first search on the current location , Find each number you can fill in and try . After searching this location, go back and continue searching .
*/
int n;
int line[10];
bool visit[10];
void print()
{
for(int i=1; i<=n; ++i)
printf("%d ", line[i]);
printf("\n");
return ;
}
void dfs(int x)
{
if(x>n)
{
print();//objective 4 altogether n After searching all the numbers, what should we do ?
}
for(int i=1; i<=n; ++i)
{
if(visit[i]) continue;//objective 1 What if this number is used ?
else
{
line[x]=i,visit[i]=1;//objective 2 If not used, search this number , What needs to be handled ? In order not to repeat how we should use visit Array tags ?
dfs(x+1);
visit[i]=0;
}
}
return;
}
int main()
{
scanf("%d",&n);
dfs(1);//objective 3 Where should we search first ?
return 0;
}边栏推荐
猜你喜欢

How to permanently set source

Hundreds of people participated. What are these people talking about in the opengauss open source community?

杭州电子商务研究院发布“数字化存在”新名词解释

Forced login, seven cattle cloud upload pictures

NIO总结文——一篇读懂NIO整个流程

Realization of background channel group management function

UVM入门实验1

MySQL Express

Flutter 渲染机制——GPU线程渲染

Unity3D 2021软件安装包下载及安装教程
随机推荐
Have a good laugh
User management - restrictions
Network IO summary
海关总署:这类产品暂停进口
Iterators and generators
First experience of tryme in opengauss
Cenos7 update MariaDB
Software test interview questions (key points)
说透缓存一致性与内存屏障
Transaction, order system add transaction
4275. Dijkstra sequence
Pass parameters and returned responses of flask
JS basic knowledge - daily learning summary ①
Element display mode: block level, inline, inline block, nesting specification, display mode conversion
02 linear structure 3 reversing linked list
接口测试工具-Postman使用详解
Horse walking oblique sun (backtracking method)
[penetration test tool sharing] [dnslog server building guidance]
Implementation of registration function
redis 网络IO