第 m 大的 n 个数全排列

DFS可过

 #include <iostream>
using namespace std;
int n,m;
int ans[];
bool flag;
int vis[];
void dfs(int x)
{
if(x>n){
m--;
if(!m) flag=;
return ;
}
if(!flag){
for(int i=;i<=n;i++)
{
if(!vis[i]&& !flag)
{
vis[i]=;
ans[x]=i;
dfs(x+);
vis[i]=;
}
}
}
}
int main()
{
while(~scanf("%d%d",&n,&m))
{
flag=;
for(int i=;i<=n;i++) vis[i]=;
dfs();
for(int i=;i<n;i++) printf("%d ",ans[i]);
printf("%d\n",ans[n]);
}
}

HDU 1027 - Ignatius and the Princess II的更多相关文章

  1. 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 ...

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

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

  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[DFS/全排列函数next_permutation]

    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 选择序列题解

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

  6. HDU 1027 Ignatius and the Princess II 排列生成

    解题报告:1-n这n个数,有n!中不同的排列,将这n!个数列按照字典序排序,输出第m个数列. 第一次TLE了,没注意到题目上的n和m的范围,n的范围是小于1000的,然后m的范围是小于10000的,很 ...

  7. hdu 1027 Ignatius and the Princess II(产生第m大的排列,next_permutation函数)

    题意:产生第m大的排列 思路:使用 next_permutation函数(头文件algorithm) #include<iostream> #include<stdio.h> ...

  8. 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 ...

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

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

随机推荐

  1. ORACLE 横表与纵表

    一.横表和纵表 横表:通常指我们平时在数据库中建立的表,是一种普通的建表方式.       (主键.字段1.字段2......)如:时间.客户ID,基本通话费.漫游通话费,国内长途费.国际长途费... ...

  2. Java 基础之 static 静态

    static表示“全局”或者“静态”的意思,用来修饰成员变量和成员方法,也可以形成静态static代码块,但是Java语言中没有全局变量的概念. 被static修饰的成员变量和成员方法独立于该类的任何 ...

  3. Struct和Class的区别

    转载至:http://blog.csdn.net/yuliu0552/article/details/6717915 C++中的struct对C中的struct进行了扩充,它已经不再只是一个包含不同数 ...

  4. D - Specialized Four-Digit Numbers

    Description Find and list all four-digit numbers in decimal notation that have the property that the ...

  5. linux学习笔记之sudo

    引用A:http://blog.chinaunix.net/uid-15811445-id-149961.html 引用B:http://os.51cto.com/art/201307/404879. ...

  6. (原+转)C++中的const修饰符

    const int a; int const a; 这两个写法是等同的,表示a是一个int常量. 简记:const后面是什么就限定什么(因为C++标准规定,const关键字放在类型或变量名之前等价的) ...

  7. 纯CSS3技术 加载中

    你能相信吗?这些都是由一个DIV元素实现的动画,纯CSS3技术 html  <div class="loader">加载中...</div> css: 图( ...

  8. Python的tkinter和tkinter.messagebox应用-鼠标和键盘命令绑定

    __author__ = 'Administrator' from tkinter import * import tkinter.messagebox class MainWindow: def b ...

  9. 利用VisualVM监测Azure云服务中的Java应用

    在做Java开发的时候,我们需要在上线之前对程序进行压力测试,对程序的性能进行全面的监控,了解JVM的CPU,内存,GC,classes,线程等等信息,或者在程序上线运行的过程当中以便于诊断问题或者对 ...

  10. JSON基础学习

    定义 JSON时轻量级的文本数据交换格式,独立于语言,比xml更小更快更易解析 JSON解析器和JSON库支持不同的编程语言 4个基本规则 1. 并列数据间用 逗号, 2. 映射用冒号表示 3. 并列 ...