diff --git a/backtracking/magic_sequence.cpp b/backtracking/magic_sequence.cpp index 336639199..6f69492e4 100644 --- a/backtracking/magic_sequence.cpp +++ b/backtracking/magic_sequence.cpp @@ -1,24 +1,25 @@ /* - * @brief [Magic sequence](https://www.csplib.org/Problems/prob019/) implementation + * @brief [Magic sequence](https://www.csplib.org/Problems/prob019/) + * implementation * * @details Solve the magic sequence problem with a backtraking - * - * "A magic sequence of length $n$ is a sequence of integers $x_0 - * \ldots x_{n-1}$ between $0$ and $n-1$, such that for all $i$ - * in $0$ to $n-1$, the number $i$ occurs exactly $x_i$ times in - * the sequence. For instance, $6,2,1,0,0,0,1,0,0,0$ is a magic - * sequence since $0$ occurs $6$ times in it, $1$ occurs twice, etc." + * + * "A magic sequence of length $n$ is a sequence of integers $x_0 + * \ldots x_{n-1}$ between $0$ and $n-1$, such that for all $i$ + * in $0$ to $n-1$, the number $i$ occurs exactly $x_i$ times in + * the sequence. For instance, $6,2,1,0,0,0,1,0,0,0$ is a magic + * sequence since $0$ occurs $6$ times in it, $1$ occurs twice, etc." * Quote of https://www.csplib.org/Problems/prob019/ * * @author [Jxtopher](https://github.com/jxtopher) */ -#include /// for std::count -#include /// for assert -#include /// IO operations -#include /// std::list -#include /// std::accumulate -#include /// std::vector +#include /// for std::count +#include /// for assert +#include /// IO operations +#include /// std::list +#include /// std::accumulate +#include /// std::vector /** * @namespace @@ -33,10 +34,9 @@ namespace backtracking { namespace magic_sequence { using sequence_t = std::vector; - /** * @brief print a magic sequence - * + * * @param s a magic sequence */ void print(const sequence_t& s) { @@ -46,11 +46,11 @@ void print(const sequence_t& s) { /** * @brief Check if it's a magic sequence - * + * * @param s a magic sequence * @return true if is a magic sequence * @return false otherwise - * + * */ bool is_magic(const sequence_t& s) { for (unsigned int i = 0; i < s.size(); i++) { @@ -63,12 +63,12 @@ bool is_magic(const sequence_t& s) { /** * @brief Filtering of sub-solutions - * + * * @param s a magic sequence - * @param depth - * @return true if the sub-solution is valid + * @param depth + * @return true if the sub-solution is valid * @return false otherwise - * + * */ bool filtering(const sequence_t& s, unsigned int depth) { return std::accumulate(s.cbegin(), s.cbegin() + depth, @@ -77,11 +77,11 @@ bool filtering(const sequence_t& s, unsigned int depth) { /** * @brief solve magic squance problem - * + * * @param s a magic sequence * @param ret list of valid magic sequences * @param depth depth in the tree - * + * */ void solve(sequence_t* s, std::list* ret, unsigned int depth = 0) { if (depth == s->size()) { @@ -102,10 +102,9 @@ void solve(sequence_t* s, std::list* ret, unsigned int depth = 0) { } // namespace backtracking - /** * @brief tests - * + * */ static void test() { backtracking::magic_sequence::sequence_t s_magic = {6, 2, 1, 0, 0,