hdoj--1027--Ignatius and the Princess II(dfs)
Ignatius and the Princess II
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?
file.
6 4
11 8
1 2 3 5 6 4
1 2 3 4 5 6 7 9 8 11 10
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int num[1010],vis[1010];
int n,ans;
bool f;
void dfs(int x)
{
if(x==n+1)
{
if(ans>0) ans--;
else
{
f=true;
for(int i=1;i<n;i++)
printf("%d ",num[i]);
printf("%d\n",num[n]);
}
}
if(f) return ;
for(int i=1;i<=n;i++)
{
if(!vis[i])
{
vis[i]=1;
num[x]=i;
dfs(x+1);
vis[i]=0;
}
}
}
int main()
{
while(scanf("%d%d",&n,&ans)!=EOF)
{
ans--;
f=false;
memset(num,0,sizeof(num));
memset(vis,0,sizeof(vis));
dfs(1);
}
return 0;
}
hdoj--1027--Ignatius and the Princess II(dfs)的更多相关文章
- 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 ( ...
- hdoj 1027 Ignatius and the Princess II 【逆康托展开】
Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ( ...
- Ignatius and the Princess II(全排列)
Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ( ...
- HDOJ.1029 Ignatius and the Princess IV(map)
Ignatius and the Princess IV 点我跳转到题面 点我一起学习STL-MAP 题意分析 给出一个奇数n,下面有n个数,找出下面数字中出现次数大于(n+1)/2的数字,并输出. ...
- HDOJ 1028 Ignatius and the Princess III (母函数)
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- 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 ...
- hdu1027 Ignatius and the Princess II (全排列 & STL中的神器)
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=1027 Ignatiu ...
随机推荐
- C 语言常用方法技巧
C语言常用方法技巧 *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !impor ...
- 汇总——WEB前端资源网
前端攻城师 爱思资源网 HTML5吧 0101后花园 前端网 编程教程和源代码示例 Javascript中文网 Web前端资源网 移动端HTML5资源整理 Web开发者 SegmentFault 前端 ...
- iOS实现图形编程可以使用三种API(UIKIT、Core Graphics、OpenGL ES及GLKit)
这些api包含的绘制操作都在一个图形环境中进行绘制.一个图形环境包含绘制参数和所有的绘制需要的设备特定信息,包括屏幕图形环境.offscreen 位图环境和PDF图形环境,用来在屏幕表面.一个位图或一 ...
- 微信小程序video
1.video是原生组件原生组件的层级是最高的,想要覆盖在video上,只能用cover-view 和 cover-image 组件,这2个可以无限嵌套.适用场景:给视频加标题: 2.检测video播 ...
- 04 学习java养成良好的写作习惯
1, 驼峰命名法 首字母大写 2, 写的时候大小中括号都补全,不忘记分号 不要都放在一行上 3, 缩进对其,tab键 4, 严格要求自己,养成良好的写作风格 5, javadoc可以将文档注释,直接生 ...
- spine骨骼动画组件使用详解
1. spine骨骼动画工具 骨骼动画: 把动画打散, 通过工具,调骨骼的运动等来形成动画spine是一个非常流行的2D骨骼动画制作工具spine 动画美术人员导出3个文件: (1) .png文 ...
- Python 索引切片
#负数开头,只有比负数大才有数据 num = [1,2,3,4,5,6,7,8,9,10] print(num[-5:5]) num = [1,2,3,4,5,6,7,8,9,10] print(nu ...
- Django - 视图获取请求头
1.urls.py(url和函数对应关系) 2.通过request.evniron,返回request的所有信息,用索引的方式,获取用户请求头信息. 3.也可以通过key,value方式,来展示请求头 ...
- [pytorch学习]1.pytorch ubuntu安装
看完了Deep Learning with Python,尝试了部分Keras的demo代码. 感觉Keras虽然容易上手,能够快速搭建出一个通用的模型,但是缺乏对底层的控制. 同时,在使用了自己编译 ...
- odoo api介绍
odoo api修饰器介绍与应用 参考文档:https://www.cnblogs.com/kfx2007/p/6093994.html 一.one one的用法主要用于self为单一集合的情况,被o ...