N个0到N个1的全排列

//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("\n");
    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

posted @ 2016-11-22 14:23  Pumpkin0227  阅读(567)  评论(0编辑  收藏  举报