Samchon Framework for CPP  1.0.0
CombinedPermutationGenerator.hpp
1 #pragma once
2 #include <samchon/library/CaseGenerator.hpp>
3 
4 namespace samchon
5 {
6 namespace library
7 {
19  : public CaseGenerator
20  {
21  private:
22  typedef CaseGenerator super;
23 
24  std::vector<size_t> dividers;
25 
26  public:
33  : super(n, r)
34  {
35  this->size_ = (size_t)pow(n, r);
36 
37  dividers.assign(r, 0);
38  for (size_t i = 0; i < r; i++)
39  {
40  size_t x = r - (i + 1);
41  dividers[i] = (size_t)pow(n, x);
42  }
43  };
44  virtual ~CombinedPermutationGenerator() = default;
45 
46  virtual auto operator[](size_t index) const->std::vector<size_t> override
47  {
48  std::vector<size_t> row(r_, 0);
49 
50  for (size_t i = 0; i < row.size(); i++)
51  row[i] = (index / dividers[i]) % n_;
52 
53  return row;
54  };
55  };
56 };
57 };
size_t size_
Size, the number of all cases.
size_t r_
R, size of elements of each case.
size_t n_
N, size of the candidates.
CombinedPermutationGenerator(size_t n, size_t r)
Construct from size of N and R.
auto r() const -> size_t
Get size of the R.
virtual auto operator[](size_t index) const -> std::vector< size_t > override
Get x&#39;th case.
auto n() const -> size_t
Get size of the N.