permutation

生成1~n的排列

#include 
#include 
using namespace std ;
void printf_permutation(int n,int *A, int cur)
{
	if(n==cur)
	{
		for (int i = 0; i < n; ++i)
		{
			printf("%d",A[i]);	
		}
		printf("\n");
	}
	else for (int i = 1; i <= n; ++i)
	{
		int ok=1;
		for (int j = 0; j < cur; ++j)
			if (A[j]==i)	
				ok=0;
		if(ok){
			A[cur]=i;
			printf_permutation(n,A,cur+1);
		}
	}
}
int main()
{
	int n;int A[100];
	scanf("%d",&n);
	printf_permutation(n,A,0);
}

 permutation_第1张图片

转载于:https://www.cnblogs.com/yzhs/p/3529934.html

你可能感兴趣的:(permutation)