#define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_11_D" #include <iostream> #include <map> #include <vector> #include "Mylib/Bit/enumerate_sets_of_size_k.cpp" namespace hl = haar_lib; int main() { std::cin.tie(0); std::ios::sync_with_stdio(false); int n, k; std::cin >> n >> k; std::map<int, std::vector<int>> ans; hl::enumerate_sets_of_size_k( k, n, [&](int d) { for (int i = 0; i < n; ++i) { if (d & (1 << i)) ans[d].push_back(i); } return true; }); for (auto& [m, v] : ans) { std::cout << m << ":"; for (auto x : v) std::cout << " " << x; std::cout << "\n"; } return 0; }
#line 1 "test/aoj/ITP2_11_D/main.test.cpp" #define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_11_D" #include <iostream> #include <map> #include <vector> #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 #line 7 "test/aoj/ITP2_11_D/main.test.cpp" namespace hl = haar_lib; int main() { std::cin.tie(0); std::ios::sync_with_stdio(false); int n, k; std::cin >> n >> k; std::map<int, std::vector<int>> ans; hl::enumerate_sets_of_size_k( k, n, [&](int d) { for (int i = 0; i < n; ++i) { if (d & (1 << i)) ans[d].push_back(i); } return true; }); for (auto& [m, v] : ans) { std::cout << m << ":"; for (auto x : v) std::cout << " " << x; std::cout << "\n"; } return 0; }