全排列
彩票随机算法
上代码
#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 ;
}

浙公网安备 33010602011771号