本文介绍了生成的子序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像0189,为此,我需要生成所有的子序列的字符串,但单个字符的顺序必须保持,也就是说,这里9不应该来之前0,1或8例:0, 018,01,09,0189,18,19,019,等等。

I have a string like "0189", for which I need to generate all subsequences, but the ordering of the individual characters must be kept, i.e, here 9 should not come before 0, 1 or 8. Ex: 0, 018, 01, 09, 0189, 18, 19, 019, etc.

另一个例子是10292,这个子序列是:1,10,02,02,09,29,92,等等。正如你可能已经注意到02两次,因为2在谈到两次给定的字符串。但同样的事情,如:21,01,91是无效的,因为为了要维持

Another example is "10292" for which subsequences would be: 1, 10, 02, 02, 09, 29, 92, etc. As you might have noticed '02' two times, since '2' comes twice in the given string. But again things like: 21, 01, 91 are invalid as order is to be maintained.

任何算法或伪code,它可以在C / C实现++将AP preciated!

Any algorithm or psuedo code, which could be implemented in C/C++ would be appreciated!

推荐答案

尝试使用递归的方法:

  • 该组子序列可以被分成包含第一字符的那些和那些不包含它
  • 包含的第一个字符的是建立通过追加字符不包含它的子序列(+仅包含第一个字符本身的序列)

这篇关于生成的子序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 04:40