jar*_*daf 2 algorithm pseudocode
我一直在寻找一种有效的单词分区算法,但没有太大的成功.例如,给定单词hello我想获得该单词的所有可能分区:{h,e,l,l,o},{h,e,l,lo},{h,e,llo} ,. ..,{你好}.我找到的所有内容都谈到了分词,这不是我的意思.
先感谢您!
您将展示一些示例,我们可以专注于逗号.是否有逗号.
Word Commas
{h,e,l,l,o} 1111
{h,e,l,l o} 1110
{h,e,l l o} 1100
...
{h e l l o} 0000
Run Code Online (Sandbox Code Playgroud)
所以很明显,在4个位置,可能有逗号或不符号,彼此独立.你需要4位来编码分区,这是2 ^ 4种可能性,我想这是16.
所以你可以形成一个循环:
for (int i = 0; i < 15; ++i)
bitsplit ("hello", i);
Run Code Online (Sandbox Code Playgroud)
迭代你的单词,同时迭代i的二进制表示的位.例如,对于11,您有位:8 + 2 + 1 = 1011设置.这意味着{h,el,l,o}.
| 归档时间: |
|
| 查看次数: |
308 次 |
| 最近记录: |