kyopro-lib

This documentation is automatically generated by online-judge-tools/verification-helper

View on GitHub

:x: Enumerate sets of size k
(Mylib/Bit/enumerate_sets_of_size_k.cpp)

Operations

Requirements

Notes

Problems

References

Verified with

Code

#pragma once

namespace haar_lib {
  template <typename Func>
  void enumerate_sets_of_size_k(int k, int n, const Func &f) {
    int c = (1 << k) - 1;
    while (c < (1 << n)) {
      if (not f(c)) break;
      const int x = c & (-c);
      const int y = c + x;
      c           = ((c & (~y)) / x >> 1) | y;
    }
  }
}  // namespace haar_lib
#line 2 "Mylib/Bit/enumerate_sets_of_size_k.cpp"

namespace haar_lib {
  template <typename Func>
  void enumerate_sets_of_size_k(int k, int n, const Func &f) {
    int c = (1 << k) - 1;
    while (c < (1 << n)) {
      if (not f(c)) break;
      const int x = c & (-c);
      const int y = c + x;
      c           = ((c & (~y)) / x >> 1) | y;
    }
  }
}  // namespace haar_lib
Back to top page