c语言排列组合问题
有N个数,有数组a[N],如何编程使所有的排列情况都遍历一遍?,n是确定数,就是排列组合不太会
程序代码:#include<stdio.h>
void dfs(bool foot[],int mem[],int depth,int n)
{
int i;
if(n == depth)
{
for(i = 0;i<n-1;i++)
printf("%d ",mem[i]);
printf("%d\n",mem[i]);
return ;
}
for(i = 0;i<n;i++)
{
if(!foot[i])
{
foot[i] = true;
mem[depth] = i+1;
dfs(foot,mem,depth+1,n);
foot[i] = false;
}
}
}
int main()
{
int i,j,n;
scanf("%d",&n);
while(n--)
{
bool foot[8] = {0};
int mem[8] = {0};
int s;
scanf("%d",&s);
dfs(foot,mem,0,s);
}
return 0;
}http://www. 深度优先搜索









