Ignatius and the Princess II

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 8497    Accepted Submission(s): 5002

Problem Description
Now our hero finds the door to the BEelzebub feng5166. He opens the door and finds feng5166 is about to kill our pretty Princess. But now the BEelzebub has to beat our hero first. feng5166 says, "I have three question for you, if
you can work them out, I will release the Princess, or you will be my dinner, too." Ignatius says confidently, "OK, at last, I will save the Princess."



"Now I will show you the first problem." feng5166 says, "Given a sequence of number 1 to N, we define that 1,2,3...N-1,N is the smallest sequence among all the sequence which can be composed with number 1 to N(each number can be and should be use only once
in this problem). So it's easy to see the second smallest sequence is 1,2,3...N,N-1. Now I will give you two numbers, N and M. You should tell me the Mth smallest sequence which is composed with number 1 to N. It's easy, isn't is? Hahahahaha......"

Can you help Ignatius to solve this problem?
 
Input
The input contains several test cases. Each test case consists of two numbers, N and M(1<=N<=1000, 1<=M<=10000). You may assume that there is always a sequence satisfied the BEelzebub's demand. The input is terminated by the end of
file.
 
Output
For each test case, you only have to output the sequence satisfied the BEelzebub's demand. When output a sequence, you should print a space between two numbers, but do not output any spaces after the last number.
 
Sample Input
6 4
11 8
 
Sample Output
1 2 3 5 6 4
1 2 3 4 5 6 7 9 8 11 10
 
Author
Ignatius.L
#include<iostream>
#include<cstring>
#include<cstdio>

using namespace
std;
const int
N = 1000 + 5;
bool
visit[N];
int
a[N],n,m,cnt; void DFS(int cur){
if(
cnt>=m) return;
if(
cur > n ){
cnt++;
if(
cnt == m)
for(int
i=1;i<=n;i++)
printf("%d%c",a[i],i<n?' ':'\n');
return;
}
for(int
i=1;i<=n;i++){
if(!
visit[i]){
visit[i] = true;
a[cur] = i;
DFS(cur + 1);
visit[i] = false;
}
}
}
int main(){
while(
scanf("%d %d",&n,&m)==2){
cnt = 0;
DFS(1);
}
}

 

搜索专题: HDU1027Ignatius and the Princess II的更多相关文章

  1. 搜索专题: HDU1026Ignatius and the Princess I

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

  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(搜索专题) 1000 N皇后问题(深度优先搜索DFS)解题报告

    前几天一直在忙一些事情,所以一直没来得及开始这个搜索专题的训练,今天做了下这个专题的第一题,皇后问题在我没有开始接受Axie的算法低强度训练前,就早有耳闻了,但一直不知道是什么类型的题目,今天一看,原 ...

  4. ACM-简单题之Ignatius and the Princess II——hdu1027

    转载请注明出处:http://blog.csdn.net/lttree Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Othe ...

  5. Ignatius and the Princess II(全排列)

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

  6. HDU1027 Ignatius and the Princess II 【next_permutation】【DFS】

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

  7. ACM-简单的主题Ignatius and the Princess II——hdu1027

    转载请注明出处:http://blog.csdn.net/lttree Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Othe ...

  8. Ignatius and the Princess II

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

  9. (next_permutation)Ignatius and the Princess II hdu102

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

随机推荐

  1. js-头部的下拉框出现与隐藏,注意加上stop??

    效果: 主要代码:

  2. Git的使用及安装

    1安装. 步骤一 如果是32位就安装32位,64位就安装64,任选一款. 步骤二 步骤三 步骤四 步骤五 步骤六 步骤七 步骤八 步骤九 步骤十 步骤十一 上面的安装完成以后,下面的程序包按要求安装就 ...

  3. jsp页面实现上传文件,并且还得支持断点续传的功能

    我们平时经常做的是上传文件,上传文件夹与上传文件类似,但也有一些不同之处,这次做了上传文件夹就记录下以备后用. 首先我们需要了解的是上传文件三要素: 1.表单提交方式:post (get方式提交有大小 ...

  4. 15 可视化工具 Navicat的简单使用

    本节重点: 掌握Navicat的基本使用 # PS:在生产环境中操作MySQL数据库还是推荐使用命令行工具mysql,但在我们自己开发测试时,可以使用可视化工具Navicat,以图形界面的形式操作My ...

  5. 实现Callable接口,并与Future结合使用

    实现步骤: 创建 Callable 接口的实现类,并实现 call() 方法,该 call() 方法将作为线程执行体,并且有返回值. 创建 Callable 实现类的实例,使用 FutureTask ...

  6. #20175201 实现mypwd

    实验要求 学习pwd命令 研究pwd实现需要的系统调用(man -k; grep),写出伪代码 实现mypwd 测试mypwd 了解pwd命令   pwd是"Print Working Di ...

  7. gitblit 数据迁移(复制)

    gitblit 数据迁移 完全拷贝方式: 将原服务器上的gitblit的安装目录.数据目录等相关目录拷到另一台服务器上即可,这样启动方式和使用端口及数据和原服务上的一模一样.(因为gitblit是不用 ...

  8. 异步实时搜索jquery select插件

    异步实时搜索jquery select插件 一.先看看效果. 二.做此插件的原因. 1.数据量过大(几千.几万条),无法一次性全部加载. 2.现有插件各不相同,无法满足功能需求. 3.美观性,可控性不 ...

  9. LinkedList Stack

  10. 点云网格化算法---MPA

    MPA网格化算法思路 第一步:初始化一个种子三角面.(随机选点,基于该点进行临近搜索到第二点:在基于该线段中点临近搜索到第三点) 图1 第二步:在种子三角面的基础上,进行面片的扩充,利用边的中点进行临 ...