全排列

彩票随机算法 

上代码


#include <cstdio>
#include <iostream>
#define MAXN 7
#define NUM 29
int num[NUM]  ;
int lottery[MAXN] ;
using namespace std ;

void combine(int n,int m)
{
    for(int i = n ;i >= m ;i--)
    {
        lottery[m-1] = num[i-1] ;
        if(m<=1)
        {
            for(int i = MAXN ;i>=0 ; i--)
                printf("%3d",lottery[i]) ;
            printf("\n") ;
        }
        else
        {
            combine(i-1,m-1) ;
        }
    }
}

int main()
{
    for(int i = 0 ;i<NUM ;i++)
    {
        num[i] = i+1 ;
    }
    for(int i  = 0;i<MAXN ;i++)
    {
        lottery[i] = 0 ;
    }
    combine(NUM,MAXN) ;
    //getch() ;
    return  0  ;
}


posted @ 2014-12-15 22:09  emoji  阅读(263)  评论(0编辑  收藏  举报