You can find here basic algorithms in C++.
This method is recursive and it is based on 5 functions:
- int first(int k) - it initialises the new number "k" with 0 ;
- int next(int k) - increases k and is verified by turn ;
- int valid(int k) - k is valid <=> conditions ;
- int is_solution(int k) - final step -> k should be equal to n or less ;
- void out() - if k meets all of the above, a {1, 2, .., k} string will be printed ;
Here I'll put some of my solutions from www.pbinfo.ro. The numebr of the problem will pe specified in the title.