HDU1027 Ignatius and the Princess II
来源:互联网 发布:网络基础设施建设问题 编辑:程序博客网 时间:2024/05/22 06:27
题目链接 :http://acm.hdu.edu.cn/showproblem.php?pid=1027
这道题可以使用字典序法求全排列
贴一个链接:http://blog.csdn.net/a510218443/article/details/70552778
#include <stdio.h>
#include <string.h>
int n,m,a[1010];
void perm()
{
int k,p,min,temp,x,i,j;
for(j=1; j<m; j++)
{
for(k=n-1; k>=0; k--)
if(a[k]<a[k+1])
break;
min=2000;
for(i=k+1; i<=n; i++)
if(a[i]>a[k])
if(a[i]<min)
{
min=a[i];
p=i;
}
temp=a[k];
a[k]=a[p];
a[p]=temp;
k=k+1;
x=n;
while(k<x)
{
temp=a[k];
a[k]=a[x];
a[x]=temp;
k++;
x--;
}
if(j==m-1)
{
for(i=1; i<=n; i++)
{
if(i==1)
printf("%d",a[i]);
else
printf(" %d",a[i]);
}
printf("\n");
}
}
}
int main()
{
int i;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(i=1; i<=n; i++)
a[i]=i;
perm();
}
return 0;
}
- hdu1027-Ignatius and the Princess II
- HDU1027 Ignatius and the Princess II
- HDU1027(Ignatius and the Princess II)
- HDU1027 Ignatius and the Princess II
- Hdu1027 Ignatius and the Princess II
- HDU1027 Ignatius and the Princess II
- HDU1027 Ignatius and the Princess II
- HDU1027 Ignatius and the Princess II
- hdu1027 Ignatius and the Princess II(排列问题)
- HDU1027 Ignatius and the Princess II 【next_permutation】【DFS】
- hdu1027 Ignatius and the Princess II(全排列)
- HDU1027 - Ignatius and the Princess II (深搜)
- ACM-简单题之Ignatius and the Princess II——hdu1027
- hdu1027 Ignatius and the Princess II (全排列 & STL中的神器)
- HDU1027——Ignatius and the Princess II(全排列)
- Ignatius and the Princess II
- Ignatius and the Princess II
- Ignatius and the Princess II
- Spring MVC小案例
- Linux触摸屏驱动-jz2440
- HDU 2846Repository(字典树+计数)
- eclipse导入工程中文乱码问题
- 浏览器对象模型---BOM
- HDU1027 Ignatius and the Princess II
- 做了一个Hanoi汉诺塔的解题c++程序,用的递归
- 71. Simplify Path
- Java对WebService实现类的方法做单元测试
- 渲染管线——透视投影变换
- CSDN如何转载别人文章
- 关于finally
- 单实例redis 的安装配置(上)
- 代码异味:Null