/*UVa129 - Krypton Factor
--回溯问题。看例子可知道确定该字符串是按照从左到右依次考虑每个位置,当前位置填不上所有的字符时,需要回溯。
--
*/
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<fstream>
#include<time.h>
#include<vector>
using namespace std;
const int maxn = 1000; char ans[maxn];
int k, L, tol;
bool flag; bool isleg(int curr){
bool res = 1;
int i, b;
for (b = 0; b < curr; b++){
int len = curr - b + 1;
if (len & 1)continue;
for (i = 0; i < len / 2; i++){
if (ans[b+i] != ans[i + b + len / 2])break;
}
if (i == len / 2)res = 0;
if (!res)break;
}
return res;
}
void dfs(int curr){
if (tol==k){ //搜索到了解
for (int i = 0; i < curr; i++){
if (i&&i % 4 == 0){
if (i%64== 0)printf("\n");
else printf(" ");
}
printf("%c", ans[i]);
}
printf("\n%d\n",curr);
flag = 1;
return;
}
if (flag)return;
for (char i = 'A'; i < 'A' + L; i++){
ans[curr] = i;
if (isleg(curr)){
tol++; //合法解,tol++
dfs(curr + 1);
}
}
}
int main(){
while (scanf("%d%d", &k, &L) && k&&L){
flag = 0;
tol = 0;
dfs(0);
}
return 0;
}

  

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. uva 129 krypton factors ——yhx

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

  8. Krypton Factor

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

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

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

随机推荐

  1. [转]mysql联合索引

    mysql联合索引   命名规则:表名_字段名1.需要加索引的字段,要在where条件中2.数据量少的字段不需要加索引3.如果where条件中是OR关系,加索引不起作用4.符合最左原则 https:/ ...

  2. Python中的多线程编程,线程安全与锁(一)

    1. 多线程编程与线程安全相关重要概念 在我的上篇博文 聊聊Python中的GIL 中,我们熟悉了几个特别重要的概念:GIL,线程,进程, 线程安全,原子操作. 以下是简单回顾,详细介绍请直接看聊聊P ...

  3. 【BestCoder #44】

    因为这场比赛,我愉快地逃掉了晚自修. T1一开始各种SillyB,忘了40%的最低限制... T2各种想吐槽... 明明OJ警告说%lld是不行的我就换成%I64D(上面写这样的)... 结果各种WA ...

  4. ZOJ 1280 Interesting Lines | 求两直线交点

    原题: 求两直线交点 思路借鉴于:http://blog.csdn.net/zxy_snow/article/details/6341282 感谢大佬 #include<cstdio> # ...

  5. 学习ExtJS4 常用控件

    ExtJS组件配置方式介绍 1.使用逗号分隔参数列表配置组件    首先来看一个简单的逗号分隔参数列表的例子.这个例子非常简单,它用来显示信息提示框. 2.使用Json对象配置组件  接下来看一个使用 ...

  6. Linux下Tcpdump使用

    1. 介绍 tcpdump是一款用来截取网络数据的工具:这里主要介绍的是为嵌入式Linux编译tcpdump的方法 2. 编译 首先去官网下载源代码, 需要下载tcpdump和libpcap, 将他们 ...

  7. Java异常throws与throw的区别

    throws关键字通常被应用在声明方法时,用来指定可能抛出的异常.多个异常可以使用逗号隔开.当在主函数中调用该方法时,如果发生异常,就会将异常抛给指定异常对象.谁调用谁处理: 抛出异常throws: ...

  8. Mex函数与C++数据矩阵交互方法

    #include "mex.h" #include <iostream> #include <windows.h> #include "math. ...

  9. virtualbox centos6.6 minimal 与宿主机win7共享文件夹

    1.virtualbox, 设置-共享文件夹,设置好共享文件夹win7dir 2.centos 创建文件夹比如share 3.mount -t vboxsf win7dir /root/share 4 ...

  10. POJ 3253 Fence Repair【哈弗曼树/贪心/优先队列】

    Fence Repair Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 53645   Accepted: 17670 De ...