hdu1027(n个数的按字典序排列的第m个序列)
题目信息:给出n。m,求n个数的按字典序排列的第m个序列
http://acm.hdu.edu.cn/showproblem.php?
pid=1027
AC代码:
/**
*全排列的个数(次序)
*/
#include<iostream>
#include<cstdio>
#include<algorithm>
int a[1001],x;
using namespace std;
void print(int n){
for(int i=1;i<n;i++){
cout<<a[i]<<" ";
}
cout<<a[n]<<endl;
}
void range(int k,int n,int m){//自定义的全排列函数(超时?
)
if(k==n) {
++x;
if(x==m){//控制全排列次数
print(n);
return;
}
}
for(int i=k;i<=n;i++){
swap(a[k],a[i]);
range(k+1,n,m);
swap(a[k],a[i]);
}
}
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF){
for(int i=1;i<=n;i++) a[i]=i;
x=0;
//range(1,n,m);
for(int i=1;i<m;i++){//进行m-1次全排列
next_permutation(a+1,a+n+1);//全排列库函数,从1開始,相当于迭代器
}
for(int i=1;i<n;i++){
cout<<a[i]<<" ";
}
cout<<a[n]<<endl;
}
return 0;
}
最新文章
- 移动端IOS点击事件失效解决方案
- 微信小程序
- Linux下Source Insight的安装和汉化
- 51nod1039 x^3 mod p
- F2063 Could not compile used unit &#39;tt.pas&#39;
- mysql 乱码问题处理
- 从客户端(xxxxxxxxxxxxxxxxxxxxxx)中检测到有潜在危险的 Request.Form 值。
- 基于Spring MVC的简单HelloWorld实例
- IOS 通过button获取cell
- CI分支kohana在线文档
- cocos2d-x 3.1.1 学习笔记[17] 关于这些活动功能
- Elasticsearch-深入理解索引原理
- LeetCode第十七题-电话号码的字母组合
- 20165214 2018-2019-2 《网络对抗技术》Exp3 免杀原理与实践 Week5
- GitHub上最受欢迎的 5 大 Java 项目
- kafka-manager配置和使用
- PAT甲题题解-1106. Lowest Price in Supply Chain (25)-(dfs计算树的最小层数)
- 02-老马jQuery教程-jQuery事件处理
- SAP中方会计凭证打印解决方案
- 兼容主流浏览器的css渐变色
热门文章
- IPhone打包工具脚本
- TensorFlow和深度学习新手教程(TensorFlow and deep learning without a PhD)
- 【DB2】If &#39;db2&#39; is not a typo you can run the following command to lookup the package that contains the binary: command-not-found db2 bash: db2: command not found
- git 的简单用法
- 域对象的引用,ActionContext 和ServletActionContext类的使用
- R语言的if-else
- U盘装系统:安装GHOST Win7系统教程
- python导入模块的两种方式
- SICP 1.23-1.26体会
- Laravel建站03--建立前台文章列表和文章详情