算法的优化。 - 页 10

 
Igor Makanu:

你的例子不是一个组合,而是一个没有重复的permutation

而我的例子是一个没有重复的连词。

哦,所以这就是它应该有的样子?

0

1

01

11

001

101

011

...


那么代码对你来说就不会太复杂,但你肯定不需要那么多循环。

 
Andrey Dik:

哦,原来是这样的计划?

我不得不在测试器中生成文件名,每个文件是一个策略参数

通过生成没有重复的组合,所有的TS组合都被组合起来,在主题的最后一页,有这样的代码


你的问题很容易在谷歌上搜索到 "无重复递归的排列组合S++"

 
Igor Makanu:

而你的问题很容易在谷歌上搜索到 "无递归递归的permutations C++"。

我在谷歌上搜索了一下,但大多没有出现普遍的解决方案。

但自己做并弄清楚它要有趣得多,信息量也大得多)。

 
Andrey Dik:

我可以得到代码吗?

input int      StartN = 5;
input int      EndN   = 7;
input int      CountN = 4;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnStart()
  {
   for(int i1=0; i1<30; i1++)
     {
      Print(CombinationGenerator(i1,StartN,EndN,CountN));
     }
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
string CombinationGenerator(uint iteration_index,int startN, int endN, int countN)
  {
   string result;
   int base=endN-startN+1;
   uint ml=base;
   for(int i1=0; i1<countN; i1++)
     {
      uint md=iteration_index%base;
      result=result+string(md+startN);
      iteration_index=(iteration_index-md)/base;
     }
   return result;
  }

这很简单。

2020.07.13 16:45:27.456 test3 (EURUSD,M1)       5555
2020.07.13 16:45:27.456 test3 (EURUSD,M1)       6555
2020.07.13 16:45:27.456 test3 (EURUSD,M1)       7555
2020.07.13 16:45:27.456 test3 (EURUSD,M1)       5655
2020.07.13 16:45:27.456 test3 (EURUSD,M1)       6655
2020.07.13 16:45:27.456 test3 (EURUSD,M1)       7655
2020.07.13 16:45:27.456 test3 (EURUSD,M1)       5755
2020.07.13 16:45:27.456 test3 (EURUSD,M1)       6755
2020.07.13 16:45:27.456 test3 (EURUSD,M1)       7755
2020.07.13 16:45:27.456 test3 (EURUSD,M1)       5565
2020.07.13 16:45:27.456 test3 (EURUSD,M1)       6565
2020.07.13 16:45:27.456 test3 (EURUSD,M1)       7565
2020.07.13 16:45:27.456 test3 (EURUSD,M1)       5665
2020.07.13 16:45:27.456 test3 (EURUSD,M1)       6665
2020.07.13 16:45:27.456 test3 (EURUSD,M1)       7665
2020.07.13 16:45:27.456 test3 (EURUSD,M1)       5765
2020.07.13 16:45:27.456 test3 (EURUSD,M1)       6765
2020.07.13 16:45:27.456 test3 (EURUSD,M1)       7765
2020.07.13 16:45:27.456 test3 (EURUSD,M1)       5575
2020.07.13 16:45:27.456 test3 (EURUSD,M1)       6575
2020.07.13 16:45:27.456 test3 (EURUSD,M1)       7575
2020.07.13 16:45:27.456 test3 (EURUSD,M1)       5675
2020.07.13 16:45:27.456 test3 (EURUSD,M1)       6675
2020.07.13 16:45:27.456 test3 (EURUSD,M1)       7675
2020.07.13 16:45:27.456 test3 (EURUSD,M1)       5775
2020.07.13 16:45:27.456 test3 (EURUSD,M1)       6775
2020.07.13 16:45:27.456 test3 (EURUSD,M1)       7775
2020.07.13 16:45:27.456 test3 (EURUSD,M1)       5556
2020.07.13 16:45:27.456 test3 (EURUSD,M1)       6556
2020.07.13 16:45:27.456 test3 (EURUSD,M1)       7556
 
Aliaksandr Hryshyn:

这很简单。

很好,谢谢!我去看看。