当前位置:网站首页>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;
}边栏推荐
- NIO示例
- After downloading URL loader and specifying the size of the image with limit, the image will not be displayed
- Flask one to many database creation, basic addition, deletion, modification and query
- Minio 安装与使用
- 691. 立方体IV
- QPushButton 按钮的创建与简单应用
- Digital intelligence innovation
- 【渗透测试工具分享】【dnslog服务器搭建指导】
- 杭州电子商务研究院发布“数字化存在”新名词解释
- How to merge multiple columns in an excel table into one column
猜你喜欢

第2章 前台数据展现

4276. Good at C

永久设置source的方法

4274. 后缀表达式

4279. 笛卡尔树

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

Eval and assert execute one sentence Trojan horse

NIO this.selector.select()

What are the differences or similarities between "demand fulfillment to settlement" and "purchase to payment"?

海关总署:这类产品暂停进口
随机推荐
Binglog backup data
How to uninstall -- Qianxin secure terminal management system
2034: [Blue Bridge Cup 2022 preliminary] pruning shrubs
User management - restrictions
Matlab 利用M文件产生模糊控制器
Oppo self-developed large-scale knowledge map and its application in digital intelligence engineering
Day5 - Flame restful request response and Sqlalchemy Foundation
Include error in vs Code (new header file)
Explain cache consistency and memory barrier
如何卸载--奇安信安全终端管理系统
Minio 安装与使用
P7 Day1 get to know the flask framework
Solution of database migration error
Supervisor 安装与使用
Cenos7 update MariaDB
Element display mode: block level, inline, inline block, nesting specification, display mode conversion
NiO Summary - read and understand the whole NiO process
Eval and assert execute one sentence Trojan horse
3428. Put apples
3428. 放苹果