- 引言:
最近准备校招,开始重拾算法,开启leetcode刷题之旅。刷到#60 Permutation Sequence 一题,憋了半天,开始Google,于是发现一个新奇的算法——康托编码。
康托展开:全排列到一个自然数的双射
X=an!+an-1!+…+ai!+…+a[1]0! ,其中a[i]为当前未出现的元素中是排在第几个(从0开始)。这就是康托展开。康托展开可用代码实现。
(使用范围:没有重复元素的全排列)
Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.