题目链接

 /*
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. vue+django前后端分析解决csrf token问题

    vue-resource post数据 参考:https://www.cnblogs.com/linxizhifeng/p/8995077.html 阅读django CsrfViewMiddlewa ...

  2. Django基础(三)_分页器、COOKIE与SESSION、FORM表单

    分页器(paginator) 分页器的使用 >>> from django.core.paginator import Paginator >>> objects ...

  3. Activity的生命周期整理

    Activity主要的三种状态: Running(运行):在屏幕前台(位于当前任务堆栈的顶部) Paused(暂停):失去焦点但仍然对用户可见(覆盖Activity可能是透明或未完全遮挡) Stopp ...

  4. 反射,hashlib模块,正则匹配,冒泡,选择,插入排序

    一.反射(自省) 首先通过一个例子来看一下本文中可能用到的对象和相关概念. import sys # 模块,sys指向这个模块对象import inspectdef foo(): pass # 函数, ...

  5. asp.net,缓存Cache

    缓存Cache: >直接使用Cache["content"],缓存与Session不同,所有用户都可以共享.永不过期,由服务器自己维护,当内存不够时,会将老的缓存释放掉. & ...

  6. P4309 [TJOI2013]最长上升子序列

    题目 P4309 [TJOI2013]最长上升子序列 做法 最长上升序列的求法肯定是烂大街了 水题是肯定的,确定出序列的位置然后套个树状数组就好了(强制在线的话改成线段树维护前缀最值也行) 所以说这题 ...

  7. rem布局原理

    昨天去面试,面试官竟然说他们用媒体查询针对不同的屏幕宽度做了9个不同的rem布局,呵呵... eg: html{font-size:20px;} div{width:16rem;height:100p ...

  8. linux的文件,目录操作命令(mv,rm,cp)

    1.mv :用于重命名文件或目录:用于转移文件或目录 重命名文件或目录:$mv filename overfile ; $mv dirname overdir(必须是当前目录下没有的,否则操作的是转移 ...

  9. 深入理解Node.js中的垃圾回收和内存泄漏的捕获

    深入理解Node.js中的垃圾回收和内存泄漏的捕获 文章来自:http://wwsun.github.io/posts/understanding-nodejs-gc.html Jan 5, 2016 ...

  10. python 中文字符的处理

    刚开始学习python的时候,都是对这英文的翻译书学习的.没有解除到中文编码的相关问题,直到自己用python去做相关的项目的时候才发先中文编码问题真的非常头疼啊.这里分享一下本人所了解的一些经验. ...