题目链接

 /*
Name:
Copyright:
Author:
Date: 2018/5/2 11:07:16
Description:输出第m小的序列
*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
int fac[] = {,,,,,,,,};//阶乘
//康托展开的逆运算,{1...n}的全排列,中的第k个数为s[]
void reverse_kangtuo(int n,int k,int s[])
{
int i, j, t, vst[]={};
--k;
for (i=; i<n; i++)
{
if (n-i- > ) {
t = k/fac[];
} else {
t = k/fac[n-i-];
}
for (j=; j<=n; j++)
if (!vst[j])
{
if (t == ) break;
--t;
}
s[i] = j;
vst[j] = ;
if (n-i- > ) {
k %= fac[];
} else {
k %= fac[n-i-];
}
}
} int main()
{
int s[] ;
int m, n;
while (cin>>m>>n) {
memset(s, , sizeof(s)) ;
reverse_kangtuo(m, n, s);
cout<<s[];
for (int i=; i<m; i++) {
cout<<" "<<s[i];
}
cout<<endl;
}
return ;
}

hdoj-1027-Ignatius and the Princess II(逆康拓展开)的更多相关文章

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

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

  2. HDU 1027 Ignatius and the Princess II(求第m个全排列)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1027 Ignatius and the Princess II Time Limit: 2000/10 ...

  3. HDU 1027 Ignatius and the Princess II(康托逆展开)

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

  4. HDU - 1027 Ignatius and the Princess II 全排列

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

  5. HDU 1027 Ignatius and the Princess II[DFS/全排列函数next_permutation]

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

  6. poj 1027 Ignatius and the Princess II全排列

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

  7. hdu 1027 Ignatius and the Princess II(正、逆康托)

    题意: 给N和M. 输出1,2,...,N的第M大全排列. 思路: 将M逆康托,求出a1,a2,...aN. 看代码. 代码: int const MAXM=10000; int fac[15]; i ...

  8. 【HDOJ】1027 Ignatius and the Princess II

    这道题目最开始完全不懂,后来百度了一下,原来是字典序.而且还是组合数学里的东西.看字典序的算法看了半天才搞清楚,自己仔细想了想,确实也是那么回事儿.对于长度为n的数组a,算法如下:(1)从右向左扫描, ...

  9. HDU 1027 Ignatius and the Princess II 选择序列题解

    直接选择序列的方法解本题,可是最坏时间效率是O(n*n),故此不能达到0MS. 使用删除优化,那么就能够达到0MS了. 删除优化就是当须要删除数组中的元素为第一个元素的时候,那么就直接移动数组的头指针 ...

随机推荐

  1. CentOS Linux中zip压缩和unzip解压缩命令详解

    以下命令均在/home目录下操作cd /home  #进入/home目录1.把/home目录下面的mydata目录压缩为mydata.zip     zip -r  mydata.zip   myda ...

  2. http,soap and rest

    http://www.cnblogs.com/hyhnet/archive/2016/06/28/5624422.html http://www.cnblogs.com/bellkosmos/p/52 ...

  3. python glob

    http://python.jobbole.com/81552/ glob模块是最简单的模块之一,内容非常少.用它可以查找符合特定规则的文件路径名.跟使用windows下的文件搜索差不多.查找文件只用 ...

  4. Linux环境下的图形系统和AMD R600显卡编程(1)——Linux环境下的图形系统简介

    转:https://www.cnblogs.com/shoemaker/p/linux_graphics01.html Linux/Unix环境下最早的图形系统是Xorg图形系统,Xorg图形系统通过 ...

  5. ACM训练小结-2018年6月23日

    今天题目情况如下:    D题:SG函数相关.    相关知识忘光...已复习.    E题:丧心病狂的模拟题目.    F题:树分块+容斥.    想到了树上莫队,但是糟糕的是不会O(1)/O(lo ...

  6. android studio Error:Unable to start the daemon process【转】

    本文转载自:https://blog.csdn.net/dhx20022889/article/details/44919905 我在用android studio 做一个小项目,在家里的mac电脑中 ...

  7. Luogu-1527 [国家集训队]矩阵乘法

    Luogu-1527 [国家集训队]矩阵乘法 题面 Luogu-1527 题解 昨天学CDQ分治时做了一些题,但是因为题(wo)太(tai)水(lan)了(le)并没有整理 学了一晚上的整体二分,拿这 ...

  8. sqlserver的疑难杂症解析

    1.电脑修改ip后ssms通过ip访问失败 通过计算机名可以访问成功,但通过修改后的ip访问却失败了! 解决方法:打开Sql Server Configuration Manager -> SQ ...

  9. Neutron新进展|DragonFlow在Mitaka版本中的Roadmap

    OpenStack网络在Mitaka版本中将有哪些新变化?1月11日到12日,DragonFlow的PTL——Eran Gampel,Kuryr的PTL——Gal Sagie,和他们的老大从以色列来到 ...

  10. 拷贝struts2项目时,运行后启动的是拷贝前的项目

    .解决方案: 然后