Created
November 3, 2025 07:29
-
-
Save Klrfl/cc511a5b77bdff3152eb5e069aaebac1 to your computer and use it in GitHub Desktop.
combination of 5 people into 3 prison cells
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <vector> | |
| #include <string> | |
| #include <algorithm> | |
| void enumerate( | |
| const int n, | |
| const int r, | |
| const int start_at, | |
| std::vector<std::string>& labels, | |
| std::vector<std::string>& enumed | |
| ) | |
| { | |
| if (enumed.size() == r) | |
| { | |
| for (auto &el : enumed) | |
| { | |
| std::cout << el << " "; | |
| } | |
| std::cout << std::endl; | |
| return; | |
| } | |
| for (int i = start_at; i < n; i++) | |
| { | |
| auto current = labels.at(i); | |
| enumed.push_back(current); | |
| enumerate(n, r, i+1 ,labels, enumed); | |
| enumed.pop_back(); | |
| } | |
| } | |
| int main() { | |
| std::vector<std::string> labels = {"Muhamad Rava Basya", "Basya", "Muhamad", "Rava", "Raba"}; | |
| int n = labels.size(), | |
| r = 3; | |
| std::vector<std::string> enumed; | |
| enumerate(n, r, 0, labels, enumed); | |
| for(const auto & i : enumed) { | |
| std::cout << i << std::endl; | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment