当前位置:网站首页>Lexicographic order -- full arrangement in bell sound
Lexicographic order -- full arrangement in bell sound
2022-06-30 07:41:00 【ASUKASS】
Write an algorithm to solve the problem of bell ringing by computer
It is known that there is 12 Oral chime , Knock randomly , So how many full permutations are there ?

We found that , You can add a shorter permutation to a highest order and move it to grow an element permutation .
So we think of recursion .

So how to arrange them all by computer ?
The dictionary order is adopted here .




Here we can find , According to the dictionary order , The last permutation should be 321, Scan from right to left , The number on the left should be strictly greater than that on the right .

1.
2. here 1 Than 3 Small , Therefore, the ratio suffix should be used ( The sequence after the descent point ) in 1 The smallest number of large , namely 2 And 1 swapping , At this time, the suffix is 31, Not the minimum suffix , therefore 31 Exchange for 213, And so on and so on , That is, you can get all the permutations .

sjt Algorithm
Define a new concept : Movable number


1. Point all numbers in the spread to the left .
2. The maximum movable number is successively exchanged with the adjacent number on the left until the end point , At the same time, one by one permutation is generated .
3. At this time, the maximum number cannot be moved , At this time, the maximum movable number is exchanged with the number of neighbors pointing to the direction , Then the direction of all the movable numbers is reversed .
4. At this time, the maximum movable number is transposed with the number pointing to the direction ...
...... You can get all the sequences by cycling .
Function implementation and call mode


边栏推荐
- 为什么大学毕业了还不知道干什么?
- 期末复习-PHP学习笔记11-PHP-PDO数据库抽象层.
- Final review -php learning notes 7-php and web page interaction
- 2021 private equity fund market report (62 pages)
- January 23, 2022 [reading notes] - bioinformatics and functional genomics (Chapter 6: multiple sequence alignment)
- Dynamic memory management
- Virtual machine VMware: due to vcruntime140 not found_ 1.dll, unable to continue code execution
- Network, network card and IP configuration
- Self study notes -- use of 74h573
- At the age of 25, I started to work in the Tiankeng industry with buckets. After going through a lot of hardships to become a programmer, my spring finally came
猜你喜欢

Personal blog one article multi post tutorial - basic usage of openwriter management tool

Introduction notes to pytorch deep learning (XII) neural network - nonlinear activation

Video player (II): video decoding

Cross compile opencv3.4 download cross compile tool chain and compile (3)

Halcon: read the camera and binary it

25岁,从天坑行业提桶跑路,在经历千辛万苦转行程序员,属于我的春天终于来了

C language implements sequential queue, circular queue and chain queue

期末复习-PHP学习笔记6-字符串处理

期末复习-PHP学习笔记3-PHP流程控制语句

STM32 register
随机推荐
深度学习——序列模型and数学符号
实验一、综合实验【Process on】
Arm debug interface (adiv5) analysis (I) introduction and implementation [continuous update]
Basic knowledge of compiling learning records
为什么大学毕业了还不知道干什么?
DXP shortcut key
深度学习——循环神经网络
How to quickly delete routing in Ad
December 13, 2021 [reading notes] | understanding of chain specific database building
Network security and data in 2021: collection of new compliance review articles (215 pages)
Examen final - notes d'apprentissage PHP 6 - traitement des chaînes
Desk lamp control panel - brightness adjustment timer
STM32 register
LabVIEW program code update is slow
深度学习——LSTM
Self study notes -- use of 74h573
Application of stack -- using stack to realize bracket matching (C language implementation)
Implementation of double linked list in C language
期末复习-PHP学习笔记9-PHP会话控制
線程池——C語言