HDU 1027 - Ignatius and the Princess II
第 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的更多相关文章
- 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 ...
- HDU 1027 Ignatius and the Princess II(康托逆展开)
Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ( ...
- HDU - 1027 Ignatius and the Princess II 全排列
Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ( ...
- 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 ( ...
- HDU 1027 Ignatius and the Princess II 选择序列题解
直接选择序列的方法解本题,可是最坏时间效率是O(n*n),故此不能达到0MS. 使用删除优化,那么就能够达到0MS了. 删除优化就是当须要删除数组中的元素为第一个元素的时候,那么就直接移动数组的头指针 ...
- HDU 1027 Ignatius and the Princess II 排列生成
解题报告:1-n这n个数,有n!中不同的排列,将这n!个数列按照字典序排序,输出第m个数列. 第一次TLE了,没注意到题目上的n和m的范围,n的范围是小于1000的,然后m的范围是小于10000的,很 ...
- hdu 1027 Ignatius and the Princess II(产生第m大的排列,next_permutation函数)
题意:产生第m大的排列 思路:使用 next_permutation函数(头文件algorithm) #include<iostream> #include<stdio.h> ...
- 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 ...
- hdoj 1027 Ignatius and the Princess II 【逆康托展开】
Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ( ...
随机推荐
- Spring--------web应用中保存spring容器
---恢复内容开始--- 问题:在一个web应用中我使用了spring框架,但有一部分模块或组件并没有托管给Spring,比如有的可能是一个webservice服务类,如果我想在这些非托管的类里使用托 ...
- C#与SQLite数据库
1.添加引用 System.Data.SQLite.dll 2.using System.Data.SQLite; 3.原理步骤: string path = "c:\\mydb.db&qu ...
- 为什么所有浏览器的userAgent都带Mozilla
参看下面链接:<为什么所有的浏览器的userAgent都带Mozilla>
- Oracle 表连接方式分析 .
一 引言 数据仓库技术是目前已知的比较成熟和被广泛采用的解决方案,用于整和电信运营企业内部所有分散的原始业务数据,并通过便捷有效的数据访问手段,可以支持企业内部不同部门,不同需求,不同层次的用户随时获 ...
- python核心编程-第五章-个人笔记
1.用del删除对对象的引用 >>> a = 123 >>> a 123 >>> del a >>> a Traceback ( ...
- ISP图像质量自动化测试方法
背景介绍 ISP(Image Signal Processor),即图像处理,主要作用是对前端图像传感器输出的信号做后期处理,主要功能有线性纠正.噪声去除.坏点去除.内插.白平衡.自动曝光控制等,依赖 ...
- Swift笔记4
字符 var str = " hello world " var kong = "" 或者 var kong = string() //定义一个空的字符 ...
- FMDB用法
iOS中原生的SQLite API在使用上相当不友好,在使用时,非常不便.于是,就出现了一系列将SQLite API进行封装的库,例如FMDB.PlausibleDatabase.sqlitepers ...
- SQL Server 文件自动增长那些事
方法 1. 把文件的增长设置为按照固定大小增长. 如filegrowth = 100MB; ------------------------------------------------------ ...
- Thread 线程简单例子
//这个方法是 静态的 public static void ThreadFunc() {//计数器 ; while(true) { //休眠1秒 Thread.Sleep(); //计数器递增 co ...