proconlib

This documentation is automatically generated by competitive-verifier/competitive-verifier

View the Project on GitHub anqooqie/proconlib

:warning: Next permutation as n-choose-r (tools/next_permutation.hpp)

template <typename Iterator>
bool next_permutation(Iterator first, Iterator k, Iterator last);

It generates the next permutation as n-choose-r. It returns true if the next permutation exists, false otherwise.

Usage

// 9-choose-3
int k = 3;
do {
  std::cout << std::string(s.begin(), std::next(s.begin(), k)) << std::endl;
} while (tools::next_permutation(s.begin(), std::next(s.begin(), k), s.end()));

Constraints

Time Complexity

License

Author

Code

#ifndef TOOLS_NEXT_PERMUTATION_HPP
#define TOOLS_NEXT_PERMUTATION_HPP

#include <algorithm>

namespace tools {

  template <typename Iterator>
  bool next_permutation(const Iterator first, const Iterator k, const Iterator last) {
    ::std::reverse(k, last);
    return ::std::next_permutation(first, last);
  }
}

#endif
#line 1 "tools/next_permutation.hpp"



#include <algorithm>

namespace tools {

  template <typename Iterator>
  bool next_permutation(const Iterator first, const Iterator k, const Iterator last) {
    ::std::reverse(k, last);
    return ::std::next_permutation(first, last);
  }
}


Back to top page