fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <cstdint>
  4. #include <algorithm>
  5. typedef std::vector<std::uint64_t> DType;
  6. typedef std::vector<DType> RType;
  7.  
  8. DType MakeSeq(std::size_t S, std::uint64_t N){
  9. DType D;
  10.  
  11. for (std::uint64_t i = 0; i < N; i++){
  12. for (std::size_t j = 0; j < S; j++){
  13. D.push_back(i+1);
  14. }
  15. }
  16.  
  17. return D;
  18. }
  19.  
  20. bool Check(DType& D){
  21. std::size_t j = 0;
  22. for (std::size_t i = 0; i < D.size()-1; i++){
  23. for (j = 0; j < D[i]; j++){
  24. if (D[i + j+1] == D[i])return false;
  25. }
  26. if (i + D[i] + 1 == D.size()) continue;
  27. if (D[i+D[i]+1] != D[i])return false;
  28. }
  29.  
  30. return true;
  31. }
  32.  
  33. RType MakeHoge(std::size_t S, std::uint64_t N){
  34. DType D = MakeSeq(S, N);
  35. RType R;
  36.  
  37. do{
  38. if (Check(D) == true) R.push_back(D);
  39. } while (std::next_permutation(D.begin(), D.end()));
  40. return R;
  41. }
  42. bool Show(RType& R){
  43. for (auto& oo : R){
  44. for (auto& o : oo){
  45. std::cout << o << ",";
  46. }
  47. std::cout << std::endl;
  48. }
  49. std::cout <<"Dump Done!"<< std::endl;
  50.  
  51. return true;
  52. }
  53.  
  54. int main(){
  55. std::size_t S = 0;//S枚
  56. std::size_t N = 0;//apper Lim N
  57. RType R;
  58.  
  59. S = 2;
  60. N = 3;
  61. R = MakeHoge(S, N);
  62. Show(R);
  63.  
  64. return 0;
  65. }
Success #stdin #stdout 0s 3276KB
stdin
Standard input is empty
stdout
2,3,1,2,1,3,
Dump Done!