Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <set>
- #include <iostream>
- #include <string>
- void generate(std::set<std::string> &set,
- std::pair<int, int>* sticks,
- const int sticksSize,
- int index) {
- if (index == sticksSize){
- std::string temp;
- for (int i = 0; i < sticksSize; i++) {
- temp += "|" + std::to_string(sticks[i].first) + "-";
- temp += std::to_string(sticks[i].second) + "|";
- temp += (i == sticksSize - 1 ? "" : " # ");
- }
- set.insert(temp);
- }else{
- for (int i = index; i < sticksSize; i++){
- std::swap(sticks[index],sticks[i]);
- generate(set, sticks, sticksSize, i + 1);
- std::swap(sticks[index].first,sticks[index].second);
- generate(set, sticks, sticksSize, i + 1);
- std::swap(sticks[index].first,sticks[index].second);
- std::swap(sticks[index],sticks[i]);
- }
- }
- }
- int main() {
- std::set<std::string> set;
- int steps; std::cin >> steps;
- std::pair<int, int> sticks[steps];
- for (int i = 0; i < steps; i++) {
- int first, second;
- std::cin >> first >> second;
- sticks[i] = std::make_pair(first, second);
- }
- generate(set, sticks, steps, 0);
- std::cout << set.size() << std::endl;
- std::set<std::string>::iterator it=set.begin();
- for (it; it!=set.end(); ++it)
- std::cout << *it << std::endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment