当前位置:网站首页>Permutations of a small feat: cantor
Permutations of a small feat: cantor
2022-07-29 20:55:00 【Cyril-KI】
1. Brief introduction
Cantor expansion is a bijection of all permutations to a natural number, which is often used for space compression when building hash tables.
For example, in all permutations containing , we define the following bijection:
The essence of Cantor expansion is to calculate the order of the current arrangement in all arrangements from small to large. It can be seen from the above figure that the sequence is the smallest and the sequence is the largest.
The formula for Cantor's expansion is:
represents the number of permutations smaller than the current permutation, so the final answer we need is, which means the number of permutations smaller than the number of positions in the current permutation from the right side of the position, pay attention to the number from the leftTo the right are.
For example: Find the Cantor expansion of .The first digit is 1, and the right side of 1 is less than 1, so , note that it is not .Similarly, there are:
, ,, so end up with:
So 24th in all ascending permutations that contain !!!
2. Code implementation
#includeusing namespace std;//First calculate the factorial of 0~9 in advance, which is convenient for calculationint fac[10]={1,1,2,6,24,120,720,5040,40320,362880};//x=a[n]*(n-1)!+a[n-1]*(n-2)!+...+a[1]*0!, note that i is from 1~n,no 0int Contor(char *a,int n) {int sum=0,small=0;for(int i=0;i>n>>a;cout< 边栏推荐
- Chrome——插件推荐
- RNA的化学修饰原理|Gal-PEG-siRNA|siRNA-S-S-DSPE|siRNA-s-s-PEG|cholesterol-siRNA
- 简单说说K均值聚类
- Verilog的时间格式系统任务----$printtimescale、$timeformat
- 【组成原理 五 系统总线】
- Kubernetes: (4) Common commands
- Unity判断字符串是否可以转为float类型
- Private domain growth | Private domain members: 15 case collections from 9 major chain industries
- 全排列的一点小技巧:康托展开
- 直播预约 | 如何通过MLOps解放和提升AI生产力?
猜你喜欢
随机推荐
LOG4J 学习
Data visualization ---- web page displays temperature and humidity
The significance of knowledge base to enterprises
[mathematical foundation] probability and mathematical statistics related concept learning
Private domain growth | Private domain members: 15 case collections from 9 major chain industries
Safe Browser will have these hidden features that will let you play around with your browser
There is a fee for the picture bed software. Forget it, I wrote an open source free one.
LeetCode_474_一和零
万字总结:分布式系统的38个知识点
ESP8266-Arduino编程实例-LittleFS及数据上传
【体系结构 一 概述】
【目标检测】Generalized Focal Loss V2
【AutoSAR 九 C/S原理架构】
internship:利用easypoi将excel表数据导入导出
ACM学习书籍简介
[GXYCTF2019] ban dolls
转行软件测试,你关心的都在这
C language advanced enumeration and joint
shell 图形化跳板机
论文写作全攻略|一篇学术科研论文该怎么写









