组合问题

Lotto
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 }

 

 

相关文章:

  • 2021-06-03
  • 2021-06-09
  • 2021-09-06
  • 2022-01-16
  • 2022-02-18
  • 2021-08-14
猜你喜欢
  • 2022-12-23
  • 2022-01-03
  • 2022-12-23
  • 2022-12-23
  • 2021-07-11
  • 2021-05-29
  • 2021-12-10
相关资源
相似解决方案