Dim x(1 To 12) As String
For i = 1 To 12
x(i) = Format(2 * i, "00")
Next
Dim temp
temp = Split(cnm(Join(x, ","), 7), "*")
For i = 0 To UBound(temp)
List1.AddItem temp(i)
Next
MsgBox List1.ListCount
End Sub
Function cnm(ByVal lottery As String, ByVal m As Integer) As String '递归代码,lottery中数字用逗号隔开
Dim temp, temp2
Dim all As String
Dim num As Integer, i As Long, j As Long
all = lottery
temp = Split(all, ",")
num = UBound(temp) + 1
If m = 1 Then cnm = Replace(all, ",", "*")
If m = 2 Then
For i = 0 To UBound(temp) - 1
For j = i + 1 To UBound(temp)
cnm = cnm & "*" & temp(i) & "," & temp(j)
Next
Next
cnm = Right(cnm, Len(cnm) - 1)
End If
If m > 2 And num >= m Then
all = Left(all, InStrRev(all, ",") - 1)
temp2 = Split(cnm(all, m - 1), "*")
For i = 0 To UBound(temp2)
If temp2(i) <> "" Then temp2(i) = temp2(i) & "," & temp(num - 1)
Next
cnm = Join(temp2, "*")
cnm = cnm & "*" & cnm(all, m)
If Left(cnm, 1) = "*" Then cnm = Right(cnm, Len(cnm) - 1)
If Right(cnm, 1) = "*" Then cnm = Left(cnm, Len(cnm) - 1)
End If
End Function
笨代码,挺快的:
Private Sub Command1_Click()
Dim x(1 To 12) As String
For i = 1 To 12
x(i) = Format(2 * i, "00")
Next
Dim num%, a%, b%, c%, d%, e%, f%, g%
num = UBound(x)
For a = 1 To num - 6
For b = a + 1 To num - 5
For c = b + 1 To num - 4
For d = c + 1 To num - 3
For e = d + 1 To num - 2
For f = e + 1 To num - 1
For g = f + 1 To num
List1.AddItem x(a) & "," & x(b) & "," & x(c) & "," & x(d) & "," & x(e) & "," & x(f) & "," & x(g)
Next
Next
Next
Next
Next
Next
Next
MsgBox List1.ListCount
End Sub
*/
#include <conio.h>
#include <stdio.h>
#include <dos.h>
#include <alloc.h>
#include <stdlib.h>
#include <string.h>
#define Max_Item 20
int Num[Max_Item];
int Cir[Max_Item];
int ZH_n;
int ZH_m;
int Chang(int Chi);
void Init_Num(int Num_count);
void Typing_Num();
void Init_Cir(int Cir_count);
void main(void)
{
int ZHUHE_count=0 ;
ZH_n = 12;
ZH_m = 3;
Init_Num(ZH_n);
Typing_Num();
Init_Cir(ZH_m);
printf("\nThe Result : \n");
for(;Cir[1]<= ((ZH_n - ZH_m) +1) ;)
{
printf("\n");
for ( int Ci = 1 ; Ci <= ZH_m ; Ci++)
{
printf("%d\t",Num[Cir[Ci]]);
}
ZHUHE_count=ZHUHE_count+1;
if ( Chang(ZH_m) <= 0 )
break;
}
printf("\nHave %d ZHUHE.\nPress any key to continue ... ",ZHUHE_count);
getch();
}
void Typing_Num()
{ printf("\n Input the MAX num count ( 3 - 10 )");
scanf("%d",&ZH_n);
for ( int Ti = 1 ; Ti<= ZH_n ; Ti ++)
{
printf("\n Enter the %d of %d ",Ti,ZH_n);
scanf("%d",&Num[Ti]);
}
printf("\n Input the num to ZHUHE (2 - %d )",ZH_n);
scanf("%d",&ZH_m);
}
void Init_Num(int Num_count)
{
for ( int i = 1 ; i<=Num_count ; i ++ )
Num[i]=i;
}
void Init_Cir(int Cir_count)
{
for ( int i = 1 ; i<=Cir_count ; i ++ )
Cir[i]=i;
}
int Chang(int Chi)
{
if ( Cir[Chi] < ( ZH_n - ZH_m + Chi ) )
{
Cir[Chi]=Cir[Chi] + 1;
return Cir[Chi]+1;
}
else
{
if ( Chi > 1 )
{
Cir[Chi] = Chang(Chi - 1);
return Cir[Chi]+1;
}
else
return 0-ZH_m; // mean Circle end .
}