📄 subject_44278.htm
字号:
<p>
序号:44278 发表者:lee 发表日期:2003-06-18 11:17:45
<br>主题:来看看复式拆分算法
<br>内容:<BR>输入为“-”分割的任意长度字符串例如12-1-123-13<BR>求出排列组合拆分后的字符串组,如上式猜解为<BR>1-1-1-1<BR>1-1-1-3<BR>1-1-2-1<BR>1-1-2-3<BR>1-1-3-1<BR>1-1-3-3<BR>2-1-1-1<BR>2-1-1-3<BR>2-1-2-1<BR>2-1-2-3<BR>2-1-3-1<BR>2-1-3-3<BR>要求算法要优化高效,因为可能拆分结果高达百万级。<BR>各位老大帮帮忙呀
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:lee 回复日期:2003-06-19 15:54:34
<br>内容:不好意思,是我没有解释清楚。<BR>比如上式输入的字符串12-1-123-13的含义是,<BR>一共有四个节点,第一个节点可能是1或者2,第二个节点只能为1,第三个节点可能为1或者2或者3,第四个节点可能为1或者3。<BR>那么拆分出所有可能的序列组合,<BR>比如第一节点选择1,第二节点因为只有一种选择为1,第三节点也选择1,第四节点也选择1,<BR>那么一种组合的情况是1-1-1-1;<BR>一共可以排列出上面写出的这些组合。<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:hsx 回复日期:2003-07-08 14:26:36
<br>内容:#include "stdio.h"<BR>#include "stdlib.h"<BR>#include "string.h"<BR><BR>char *array = "12-1-123-13";<BR><BR>void go(char *gg, int cc, unsigned int *pp, int *ppn, int nn)<BR>{<BR> int i;<BR> char *ppp =(char *)pp[nn];<BR><BR> if (0 == ppn[nn])<BR> {<BR> for (i=0; i<cc; i++)<BR> {<BR> printf("%c-",gg[i]);<BR> }<BR> printf("\n");<BR> return;<BR> }<BR><BR> for (i=0; i<ppn[nn]; i++)<BR> {<BR> gg[cc] = ppp[i];<BR> go(gg, cc+1, pp, ppn, nn+1);<BR> }<BR>}<BR><BR>void main()<BR>{<BR> int i, len, nindex = 0;<BR><BR> unsigned int *p;<BR> int *n;<BR> char *g;<BR><BR> //actually, len is the count of '-' in array<BR> // plus 1, but i am lazy, not calculate the<BR> //count of '-';<BR> len = strlen(array);<BR><BR> p = new unsigned int[len];<BR> n = new int[len];<BR> g = new char[len];<BR><BR> for (i=0; i<len; i++)<BR> {<BR> p[i] = 0;<BR> n[i] = 0;<BR> }<BR><BR> p[nindex] = (unsigned int)array;<BR> for (i=0; i<len; i++)<BR> {<BR> if ('-' == array[i])<BR> {<BR> nindex++;<BR> p[nindex] = (unsigned int)&array[i+1];<BR><BR> continue;<BR> }<BR><BR> n[nindex]++;<BR> }<BR><BR> go(g, 0, p, n, 0);<BR><BR> delete[] p;<BR> delete[] n;<BR> delete[] g;<BR>}
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:lee 回复日期:2003-07-09 09:50:01
<br>内容:万分感谢
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -