题意:

一个字符串含有两个相邻的重复的子串,则称这个串为容易的串,其他为困难的串,对于给定n,l,求出由前l个字符组成的字典序第n小的困难的串。

分析:

按字典序在字符串末尾增加新的字符,并从当前字符串后缀入手,判断长度为偶数的子串中,是否含有重复的相邻子串。

代码:

#include<cstdio>
#include<iostream>
using namespace std;
int n, l, cnt;
int s[85];
int dfs(int cur)
{
if(cnt++== n){
for(int i = 0; i < cur; i++){
if(i%64 == 0 && i>0) cout<<endl;
else if(i>0 && i%4 == 0) cout<<' ';
cout<<(char)(s[i]+'A');
}
cout<<endl<<cur<<endl;
return 1;
}
for(int i = 0; i < l; i++){
s[cur] = i;
int ok = 1;
for(int j = 1; j * 2 <= cur + 1; j++){
int e = 1;
for(int k = 0; k < j; k++){
if(s[cur - k]!=s[cur - k - j]) {e = 0;break;}
}
if(e){ ok = 0;break;}
}
if(ok) if(dfs(cur+1)) return 1 ;
}
return 0;
}
int main (void)
{
while(cin>>n>>l&&n) {
cnt = 0;
dfs(0);
}
}

UVA 129_ Krypton Factor的更多相关文章

  1. UVA.129 Krypton Factor (搜索+暴力)

    UVA.129 Krypton Factor (搜索+暴力) 题意分析 搜索的策略是:优先找长串,若长串不合法,则回溯,继续找到合法串,直到找到所求合法串的编号,输出即可. 注意的地方就是合法串的判断 ...

  2. Uva 129 Krypton Factor

    0.这道题的输出 处理起来挺麻烦的 以后类似的可以借鉴一下 ;i<cur;i++) { && i%==) printf("\n%c",a[i]); & ...

  3. UVa 129 Krypton Factor【回溯】

    学习的紫书的回溯,理解起来还是好困难的说啊= = #include<iostream> #include<cstdio> #include<cstring> #in ...

  4. UVa 129 Krypton Factor困难的串 (dfs 递归搜索)

    回溯法,只需要判断当前串的后缀,而不是所有的子串 #include<iostream> #include<cstdio> using namespace std; ]; int ...

  5. UVA - 129 Krypton Factor (困难的串)(回溯法)

    题意:求由字母表前L个字母组成的字典序第n小的困难串.(如果一个字符串包含两个相邻的重复子串,则称它是"容易的串",其他串称为"困难的串".) 分析:回溯时,检 ...

  6. UVa 129 Krypton Factor (DFS && 回溯)

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

  7. UVA129 Krypton Factor 困难的串 dfs回溯【DFS】

     Krypton Factor Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  8. uva 129 krypton factors ——yhx

     Krypton Factor  You have been employed by the organisers of a Super Krypton Factor Contest in which ...

  9. Krypton Factor

    Krypton Factor Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

随机推荐

  1. java数据结构和算法04(链表)

    前面我们看了数组,栈和队列,大概就会这些数据结构有了一些基本的认识,首先回顾一下之前的东西: 在数组中,其实是分为有序数组和无序数组,我简单实现了无序数组,为什么呢?因为有序数组的实现就是将无序数组进 ...

  2. iOS programming UITableView and UITableViewController

    iOS programming  UITableView and UITableViewController A UITableView displays a single column of dat ...

  3. iOS programming UITabBarController

    iOS programming UITabBarController 1.1 View controllers become more interesting when the user's acti ...

  4. Node.js——网站访问一般流程

  5. Vuex/Vue 练手项目 在线汇率转换器

    详情请点击: https://zhuanlan.zhihu.com/p/33362758

  6. html5开发移动混合App系列1-开发环境搭建

    最近公司准备开发门店收银系统,是基于IPAD的程序,决定采用基于 Ionic + Cordova + AngularJS技术混合开发模式. 准备 一台mac(安装了mac os的虚拟机也可以),nod ...

  7. 怎样在nexus 中 搜索到远程maven仓库中的jar 文件

    怎样在nexus 中 搜索到远程maven仓库中的jar 文件 url: http://www.oschina.net/question/95712_21999 点击Administration菜单下 ...

  8. 服务器设置禁ping

    //设置Linux服务器禁ping!!!终端命令行直接输入 echo 1 >/proc/sys/net/ipv4/icmp_echo_ignore_all 这个是关闭ping的命令. 如果你想要 ...

  9. js 给url添加时间戳 解决浏览器缓存

    //解决浏览器缓存 function timestamp(url){      //  var getTimestamp=Math.random(); var getTimestamp=new Dat ...

  10. cc.AudioSource

    cc.AudioSource1:AudioSource组件是音频源组件, 发出声音的源头2: AudioSource组件面板: clip: 声源的播放的音频对象: AudioClip, mp3, wa ...