组合问题 ZOJ 1089 Lotto
组合问题
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<iostream>
2 using namespace std;
3 int m;
4 int n = 6;
5 int b[13];
6 int c[13];
7 void combination(int, int);
8
9 int main()
10 {
11 int num;
12 //freopen("test.txt","r", stdin);
13 cin >> num;
14 while (num)
15 {
16 for (int i = 0; i < num; i++)
17 {
18 cin >> c[i];
19 }
20 m = num;
21 combination(0,0);
22 cin >> num;
23 if (num)
24 cout << endl;
25 }
26
27 return 0;
28 }
29
30 //计算组合数
31 //m个里面取6个出来
32 void combination(int i, int current)
33 {
34 if (i >= n)
35 {
36 for ( int j = 0; j < n; j++)
37 {
38 if (j == n-1)
39 cout << b[j];
40 else
41 cout << b[j] << " ";
42 }
43 cout << endl;
44 }
45 else
46 {
47 for (int j = current; j < m-n+i+1; j++)//这里j的上限做了优化,减小不必要的分枝
48 {
49 b[i] = c[j];
50 combination(i+1, j+1);
51 }
52 }
53 }