Algorithm to generate all combinations of a string with length n to 1 [closed]

女生的网名这么多〃 提交于 2019-12-12 03:07:07

问题


I am looking for help with an algorithm that will generate all the possible combinations of n-random letters in decreasing length. For example, the array of 'a','b','c' should generate:

abc acb bac bca cab cba ab ac ba bc ca cb a b c

where letters cannot repeat themselves once used


回答1:


"Permutation with decresing length" is basically just a loop of standard permutation task.:

  • you are given a set of n letters
  • take each letter and add it to the output
  • take all possible pairs of letters and add them to the output
  • take all possible triplets of letters and add them to the output
  • ... do until you reach N


来源:https://stackoverflow.com/questions/27561212/algorithm-to-generate-all-combinations-of-a-string-with-length-n-to-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!