
8

一道全序列排序的算法题求算法
source link: https://www.v2ex.com/t/847783
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

题目要求
在数学中 n 个元素的排序序列有 n !种,我们将 1 到 n 的连续自然数进行全序列排序,会有 n !个排序,排序形成的结果数据按从小到大排列。
编写一个程序
实现输入 x 和 n ,输出 n!种排序中第 x 小的自然数排序序列。
举例 n=2; 全序列排序有 2 个种,1 ,2 和 2 ,1
程序
输入 x=1 ,则输出 1 ,2
输入 x=2 ,则输出 2 ,1
算法要求
不允许暴力递归,进行计算,因为最坏的复杂度是 o(n!),性能太差
不允许存储全序列 n !个数组,全序列数组针对 n 较大的情况下,空间占用过大。
尽可能降低算法时间复杂度。
看看哪个大神会做,我在编写加密算法遇到的一个问题
在数学中 n 个元素的排序序列有 n !种,我们将 1 到 n 的连续自然数进行全序列排序,会有 n !个排序,排序形成的结果数据按从小到大排列。
编写一个程序
实现输入 x 和 n ,输出 n!种排序中第 x 小的自然数排序序列。
举例 n=2; 全序列排序有 2 个种,1 ,2 和 2 ,1
程序
输入 x=1 ,则输出 1 ,2
输入 x=2 ,则输出 2 ,1
算法要求
不允许暴力递归,进行计算,因为最坏的复杂度是 o(n!),性能太差
不允许存储全序列 n !个数组,全序列数组针对 n 较大的情况下,空间占用过大。
尽可能降低算法时间复杂度。
看看哪个大神会做,我在编写加密算法遇到的一个问题
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK