[各种面试题] 困难的数

来源:互联网 发布:js点击显示隐藏div 编辑:程序博客网 时间:2024/06/05 08:11

题目大意:如果一个字符串包含两个相邻的重复子串,则称它是容易的串,其他串称为“困难的串”。例如:BB,ABCDACABCAB吗,ABCDSABCD都是容易的串,而D,DC,ABDAB,CBABCBA都是困难的。


void getKth(int k,int l){string hard;dfs(0,l,hard);}void dfs(int k,int l,string& hard){if ( k== n )return;for(int i=0;i<l;i++){hard.pb(i+'A');int ok=1;int sz=hard.size();for(int len=1;len*2<=sz;len++){int same=1;for(int j=0;j<len;j++){if ( hard[sz-1-j]!=hard[sz-1-j-len]){same=0;break;}}if ( same ){ok=0;break;}}if ( ok ){cout<<hard.c_str()<<endl;dfs(k+1,l,hard);}hard.pop_back();}}


原创粉丝点击