-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnCr.cc
More file actions
39 lines (37 loc) · 742 Bytes
/
nCr.cc
File metadata and controls
39 lines (37 loc) · 742 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <vector>
struct combinations {
typedef std::vector<int> combination_t;
combinations(int n, int r)
: n(n),
r(r)
{
// initialize the value of curr
for (auto i = 0; i < r; i++)
{
curr.push_back(i);
}
--curr[r - 1];
}
public:
combination_t
next_combination()
{
for (auto i = r - 1; i > 0; i--)
{
curr[i] = ++curr[i] % n;
if (curr[i] != 0) {
break;
}
}
return curr;
}
private:
combination_t curr;
int n; // total number of items
int r; // number of items to combinee at a given time
};
int
main (int argc, char *argv[])
{
return 0;
}