给出一个字符串:
String words = "Mary had a little lamb";
如何获得句子片段的组合而发生的话,在原句的顺序保持???
how to obtain a combination of sentence fragments while the order of occurrence of words in the original sentence is maintained ???
例如:
{'Mary had a little lamb'}
{'Mary had a little', 'lamb'}
{'Mary had a', 'little lamb'}, {'Mary had a', 'little', 'lamb'}
{'Mary had', 'a little lamb'}, {'Mary had', 'a little', 'lamb'}, {'Mary had', 'a', 'little lamb'}, {'Mary had', 'a', 'little', 'lamb'}
{'Mary', 'had a little lamb'}, {'Mary', 'had a little', 'lamb'}, {'Mary', 'had a', 'little lamb'} and so on...
在此先感谢:)
Thanks in advance :)
想想看这样的:
Mary <1> had <2> a <3> little <4> lamb
所有这些&LT;数量&GT;
S可以是真或假。如果这是真的,那么你就砍了一句在该位置。
Each of these <number>
s can be either true or false. If it is true, then you cut the sentence in that location.
因此,如果有n + 1个词,你的问题得到减少到经历具有n位数字的二进制重新presentation,即从0到2 ^ n-1个
So, if you have n+1 words, your problem gets reduced to going through binary representation of numbers with n bit, that is from 0 to 2^n-1
例如:
0110 -> {'Mary had', 'a', 'little lamb'}
1111 -> {'Mary', 'had', 'a', 'little', 'lamb'}
0001 -> {'Mary had a little', 'lamb'}
1011 -> {'Mary', 'had a', 'little', 'lamb'}
下一篇:创建向外螺向外