//N个0到N个1的全排列 #include <stdio.h> #include <stdlib.h> #define SIZE 20 int num;//N个 int data[SIZE] = {}; void quanpailie(int step){ if(step == num){ for(int i=0;i<num;i++){ //0,1,2 printf("%d",data[i]);} printf(" "); return; } data[step]=0; quanpailie(step+1); data[step]=1; quanpailie(step+1); } int main(){ freopen("input.txt","r",stdin); scanf("%d",&num);//读入全排列的个数num---num个0到num个1的全排列 quanpailie(0); //system("pause"); }
测试用例:
input.txt
5