排列问题
来源:互联网 发布:万方数据库免费注册 编辑:程序博客网 时间:2024/05/22 14:40
#include<cstdio>
#include<math.h>
int a[10],n,r;
void search(int top)
{
int i,j;
bool p;
if(top>r)
{
for(int t=1;t<=r;t++)printf("%d",a[t]);
printf("\n");
}
else
{
for(i=1;i<=n;i++)
{
p=true;
if(top==1)
{
a[top]=i;
search(top+1);
}
if(top>1)
{
j=1;
while(j<top&&p==true)
{
if(i==a[j])p=false;
else j++;
}
if(p==true)
{
a[top]=i;
search(top+1);
}
}
}
}
}
int main()
{
int top=1;
scanf("%d %d",&n,&r);
search(top);
return 0;
}
#include<math.h>
int a[10],n,r;
void search(int top)
{
int i,j;
bool p;
if(top>r)
{
for(int t=1;t<=r;t++)printf("%d",a[t]);
printf("\n");
}
else
{
for(i=1;i<=n;i++)
{
p=true;
if(top==1)
{
a[top]=i;
search(top+1);
}
if(top>1)
{
j=1;
while(j<top&&p==true)
{
if(i==a[j])p=false;
else j++;
}
if(p==true)
{
a[top]=i;
search(top+1);
}
}
}
}
}
int main()
{
int top=1;
scanf("%d %d",&n,&r);
search(top);
return 0;
}
0 0
- 排列问题
- 排列问题
- 排列问题
- 排列问题
- 排列问题
- 排列问题
- 排列问题
- 排列问题
- 排列问题
- 排列问题
- 排列问题
- 排列问题
- 排列问题
- 排列问题
- 排列问题
- 排列问题
- 排列问题
- 排列问题
- iOS App图标和启动画面尺寸
- iOS9 3DTouch、ShortcutItem、Peek And Pop
- C语言语法基础--黑马程序员
- OOD(面向对象)编程规范
- 欢迎使用CSDN-markdown编辑器
- 排列问题
- 三星题 6.20八皇后问题
- 数据结构实验之串一:KMP简单应用
- WPF的资源(Resource)?
- python汉诺塔算法
- 安卓布局参数
- Cg shader with image-based diffuse lighting
- 个人总结 mysql 中文乱码
- 数组、指针和字符串(二)------C++学习笔记