Skip to content

Commit 08319f0

Browse files
authored
枚举组合
1 parent 73f1068 commit 08319f0

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

Combination.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include <cstdio>
2+
3+
using namespace std;
4+
5+
int sc, rc;
6+
bool sel[50010];
7+
8+
// Take m stone(s) last n stone(s).
9+
void enum_combination(int n, int m)
10+
{
11+
if (m == 0)
12+
{
13+
for (int i = 0; i < sc; i++)
14+
{
15+
if (sel[i])
16+
{
17+
printf("%d ", i);
18+
}
19+
}
20+
printf("\n");
21+
return;
22+
}
23+
24+
if (n > m)
25+
{
26+
sel[sc - n - 1] = true;
27+
enum_combination(n - 1, m - 1);
28+
sel[sc - n - 1] = false;
29+
enum_combination(n - 1, m);
30+
}
31+
else
32+
{
33+
sel[sc - n - 1] = true;
34+
enum_combination(n - 1, m - 1);
35+
}
36+
sel[sc - n - 1] = false;
37+
}
38+
39+
int main()
40+
{
41+
scanf("%d%d", &sc, &rc);
42+
sc += 2;
43+
enum_combination(sc - 2, rc);
44+
45+
return 0;
46+
}

0 commit comments

Comments
 (0)