Background\text{Background}Background

The \text{The }The Listen&Say Test will be hold on May 11, so I decided to fill my blog \text{Test will be hold on May 11, so I decided to fill my blog }Test will be hold on May 11, so I decided to fill my blog 

with English words until that day.\text{with English words until that day.}with English words until that day.

Problem\text{Problem}Problem

There goes a problem.\text{There goes a problem.}There goes a problem.

You’ve got 2 intergers N,k. Please calculate the kth permutation of ∀k∈[i,n].\text{You've got 2 intergers }N,k\text{. Please calculate the }k\text{th permutation of }\forall k\in[i,n].You’ve got 2 intergers N,k. Please calculate the kth permutation of ∀k∈[i,n].

Solution\text{Solution}Solution

It’s easy to know that we can got it by Depth-first Search, \text{It's easy to know that we can got it by Depth-first Search, }It’s easy to know that we can got it by Depth-first Search, but its Time complexity is O(n!).\text{but its Time complexity is }O(n!).but its Time complexity is O(n!).

DeCantor Expansion is a algorithm which can solve problems like these calculating the kth permutation\text{is a algorithm which can solve problems like these calculating the }k\text{th permutation}is a algorithm which can solve problems like these calculating the kth permutationin O(nlog⁡n) with heap optimization.\text{in }O(n\log n)\text{ with heap optimization.}in O(nlogn) with heap optimization.



Let’s explain how it works in a simple example. Set N=5,k=61, the answer is a[].\text{Let's explain how it works in a simple example. Set }N=5,k=61,\text{ the answer is }a[].Let’s explain how it works in a simple example. Set N=5,k=61, the answer is a[].

1.Let 61 / 4! = 2 ... 13, it shows that there’re 2 numbers behind a[1] are smaller than a[1].\text{1.\quad Let 61 / 4! = 2 ... 13, it shows that there're 2 numbers behind }a[1]\text{ are smaller than a[1].}1.Let 61 / 4! = 2 ... 13, it shows that there’re 2 numbers behind a[1] are smaller than a[1].

Therefore, a[1]=3;\text{Therefore, }a[1]=3;Therefore, a[1]=3;

2.Let 13 / 3! = 2 ... 1, it shows that there’re 2 numbers behind a[2] are smaller than a[2].\text{2.\quad Let 13 / 3! = 2 ... 1, it shows that there're 2 numbers behind }a[2]\text{ are smaller than a[2].}2.Let 13 / 3! = 2 ... 1, it shows that there’re 2 numbers behind a[2] are smaller than a[2].

Therefore, a[2]=4;\text{Therefore, }a[2]=4;Therefore, a[2]=4;

3.Let 1 / 2! = 0 ... 1, it shows that there’re 0 number behind a[3] are smaller than a[3].\text{3.\quad Let 1 / 2! = 0 ... 1, it shows that there're 0 number behind }a[3]\text{ are smaller than a[3].}3.Let 1 / 2! = 0 ... 1, it shows that there’re 0 number behind a[3] are smaller than a[3].

Therefore, a[3]=1;\text{Therefore, }a[3]=1;Therefore, a[3]=1;

4.Let 1 / 1! = 1 ... 0, it shows that there’re 1 number behind a[4] are smaller than a[4].\text{4.\quad Let 1 / 1! = 1 ... 0, it shows that there're 1 number behind }a[4]\text{ are smaller than a[4].}4.Let 1 / 1! = 1 ... 0, it shows that there’re 1 number behind a[4] are smaller than a[4].

Therefore, a[4]=5;\text{Therefore, }a[4]=5;Therefore, a[4]=5;



Therefore, a[5]=2,a[]={3,4,1,5,2}.\text{Therefore, }a[5]=2, a[]=\{3,4,1,5,2\}.Therefore, a[5]=2,a[]={3,4,1,5,2}.

Summary\text{Summary}Summary

∀i∈[1,n−1], let k / (n−1)!, the answer you’ve got is the number of interger j∈[i+1,n] which has a[j]&lt;a[i]. And let k equals to the remainder.\forall i\in[1,n-1],\text{ let }k\ /\ (n-1)!\text{, the answer you've got is the number of interger }\newline j\in[i+1,n]\text{ which has }a[j]&lt;a[i].\text{ And let }k\text{ equals to the remainder.}∀i∈[1,n−1], let k / (n−1)!, the answer you’ve got is the number of interger j∈[i+1,n] which has a[j]<a[i]. And let k equals to the remainder.

The End\text{The End}The End

Reference material\text{Reference material}Reference material

DeCantor Expansion (逆康托展开)的更多相关文章

  1. LightOJ1060 nth Permutation(不重复全排列+逆康托展开)

    一年多前遇到差不多的题目http://acm.fafu.edu.cn/problem.php?id=1427. 一开始我还用搜索..后来那时意外找到一个不重复全排列的计算公式:M!/(N1!*N2!* ...

  2. nyoj 139——我排第几个|| nyoj 143——第几是谁? 康托展开与逆康托展开

    讲解康托展开与逆康托展开.http://wenku.baidu.com/view/55ebccee4afe04a1b071deaf.html #include<bits/stdc++.h> ...

  3. 题解报告:NYOJ 题目143 第几是谁?(逆康托展开)

    描述 现在有"abcdefghijkl”12个字符,将其按字典序排列,如果给出任意一种排列,我们能说出这个排列在所有的排列中是第几小的.但是现在我们给出它是第几小,需要你求出它所代表的序列. ...

  4. HDU1027 Ignatius and the Princess II( 逆康托展开 )

    链接:传送门 题意:给出一个 n ,求 1 - n 全排列的第 m 个排列情况 思路:经典逆康托展开,需要注意的时要在原来逆康托展开的模板上改动一些地方. 分析:已知 1 <= M <= ...

  5. 康托展开&逆康托展开学习笔记

    啊...好久没写了...可能是最后一篇学习笔记了吧 题目大意:给定序列求其在全排列中的排名&&给定排名求排列. 这就是康托展开&&逆康托展开要干的事了.下面依次介绍 一 ...

  6. Codeforces-121C(逆康托展开)

    题目大意: 给你两个数n,k求n的全排列的第k小,有多少满足如下条件的数: 首先定义一个幸运数字:只由4和7构成 对于排列p[i]满足i和p[i]都是幸运数字 思路: 对于n,k<=1e9 一眼 ...

  7. hdoj 1027 Ignatius and the Princess II 【逆康托展开】

    Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ( ...

  8. 康托展开与逆康托展开模板(O(n^2)/O(nlogn))

    O(n2)方法: namespace Cantor { ; int fac[N]; void init() { fac[]=; ; i<N; ++i)fac[i]=fac[i-]*i; } in ...

  9. 【HDU - 1043】Eight(反向bfs+康托展开)

    Eight Descriptions: 简单介绍一下八数码问题:在一个3×3的九宫格上,填有1~8八个数字,空余一个位置,例如下图: 1 2 3 4 5 6 7 8   在上图中,由于右下角位置是空的 ...

随机推荐

  1. JAVA多线程高并发面试题总结

    ReadMe : 括号里的内容为补充或解释说明. 多线程和高并发是毕业后求职大厂面试中必问的知识点,自己之前总是面试前才去找相关的知识点面试题来背背,隔段时间又忘了,没有沉淀下来,于是自己总结了下相关 ...

  2. redis的几个知识点

    Redis的全称是Remote Dictionary Server,即远程字典服务,通常用作服务器缓存服务. 这里通过Redis的几个知识点来了解Redis. Redis的通讯协议 Redis的通讯协 ...

  3. windows任务计划定时备份sqlserver数据库

    使用windows的任务计划新建一个sqlserver数据库的定时备份任务 一.      (我是以sqlserver2008r2数据库版本测试的)在G盘下新建文集夹Database_backup,首 ...

  4. 纯css耍个透明正方体转一转

    效果 效果图如下 ​ 实现思路 定义一个最外层的容器,用来控制显示的位置 定义一个父容器,用来设置元素被查看位置的视图,这里使用到CSS3的perspective 属性 定义子容器,设置为相对定位,利 ...

  5. 豆瓣电影TOP250和书籍TOP250爬虫

    豆瓣电影 TOP250 和书籍 TOP250 爬虫 最近开始玩 Python , 学习爬虫相关知识的时候,心血来潮,爬取了豆瓣电影TOP250 和书籍TOP250, 这里记录一下自己玩的过程. 电影 ...

  6. netCDF4 not installed properly - DLL load failed (netCDF4安装问题)

    环境描述:windows10 ,conda,python3.6 问题描述:netCDF4是python中用来处理地球气象数据的文件读取包,在安装完成后,from netCDF4 import Data ...

  7. 深度学习论文翻译解析(五):Siamese Neural Networks for One-shot Image Recognition

    论文标题:Siamese Neural Networks for One-shot Image Recognition 论文作者: Gregory Koch   Richard Zemel Rusla ...

  8. Hbase入门(三)——数据模型

    Hbase最核心但也是最难理解的就是数据模型,由于与传统的关系型数据库不同,虽然Hbase也有表(Table),也有行(Row)和列(Column),但是与关系型数据库不同的是Hbase有一个列族(C ...

  9. 配置eclipse编写html/js/css/jsp/java时自动提示

    配置eclipse编写html/js/css/jsp/java时自动提示步骤: 1.打开eclipse→Windows→Preferences→Java→Editor→Content Assist 修 ...

  10. 深度解密Go语言之反射

    目录 什么是反射 为什么要用反射 反射是如何实现的 types 和 interface 反射的基本函数 反射的三大定律 反射相关函数的使用 代码样例 未导出成员 反射的实际应用 json 序列化 De ...