学习的紫书的回溯,理解起来还是好困难的说啊= =

 #include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
using namespace std; typedef long long LL;
const int INF = (<<)-;
const int mod=;
const int maxn=; char s[maxn];
int n,L,cnt,sum; int dfs(int cur){
if(cnt++==n){
int tmp=;
for(int i=;i<cur;i++) {
if(i%==&&i) printf("\n");
else if(i%==&&i) printf(" ");
printf("%c",'A'+s[i]);
}
printf("\n");
printf("%d\n",cur);
return ;
} for(int i=;i<L;i++){
s[cur]=i;
int ok=;
for(int j=;j*<=cur+;j++){
int equal=;
for(int k=;k<j;k++)
if(s[cur-k]!=s[cur-k-j]){equal=;break;}
if(equal){ok=;break;}//后一半等于前一半,不符合困难的串的条件
}
if(ok) if(!dfs(cur+)) return ;
}
return ;
} int main(){
while(scanf("%d %d",&n,&L)!=EOF&&n&&L){
cnt=;
dfs();
}
return ;
}

加油啊 go---go---go-

UVa 129 Krypton Factor【回溯】的更多相关文章

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

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

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

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

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

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

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

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

  5. Uva 129 Krypton Factor

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

  6. 129 - Krypton Factor

    /*UVa129 - Krypton Factor --回溯问题.看例子可知道确定该字符串是按照从左到右依次考虑每个位置,当前位置填不上所有的字符时,需要回溯. -- */ #define _CRT_ ...

  7. uva 129 krypton factors ——yhx

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

  8. UVA 129_ Krypton Factor

    题意: 一个字符串含有两个相邻的重复的子串,则称这个串为容易的串,其他为困难的串,对于给定n,l,求出由前l个字符组成的字典序第n小的困难的串. 分析: 按字典序在字符串末尾增加新的字符,并从当前字符 ...

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

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

随机推荐

  1. Unity3D 批量图片资源导入设置

    原地址:http://blog.csdn.net/asd237241291/article/details/8433548 创文章如需转载请注明:转载自 脱莫柔Unity3D学习之旅 QQ群:[] 本 ...

  2. asp.net 处理流程

    原文:http://www.cnblogs.com/wupeiqi/archive/2013/03/03/2941295.html 工作进程: 在iis中,工作进程(w3wp.exe)运行着asp.n ...

  3. Oracle MySQL

    http://blog.jobbole.com/46510/ http://blackproof.iteye.com/blog/1570456 http://blog.csdn.net/yzsind/ ...

  4. Spring mvc json null

    http://blog.csdn.net/zdsdiablo/article/details/9429263

  5. zoj 2290 Game 博弈论

    思路:HDU有过类似的题目,也就是谁面对FIB数,就处于必败状态. 再求第二问的时候要注意不一定要在一步之内就让对手处于必败状态,可以多步进行, 这个过程可以用递归实现. 代码如下: #include ...

  6. Linux客户/服务器程序设计范式2——并发服务器(进程池)

    引言 让服务器在启动阶段调用fork创建一个子进程池,通过子进程来处理客户端请求.子进程与父进程之间使用socketpair进行通信(为了方便使用sendmsg与recvmsg,如果使用匿名管道,则无 ...

  7. MyEclipse 2015 CI

    系统 win8.1 MyEclipse 2015 CI 激活后可用 激活工具 地址:http://download.csdn.net/detail/trep10000/8305577

  8. 斐波那契数列公式算法-JS实现

    之前算斐波那契数列都是算前两个数相加实现的 比如0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233,377,610,987,1597,2584,4181 ...

  9. 【poj1284-Primitive Roots】欧拉函数-奇素数的原根个数

    http://poj.org/problem?id=1284 题意:给定一个奇素数p,求p的原根个数. 原根: { (xi mod p) | 1 <= i <= p-1 } is equa ...

  10. jd-gui 反编译后去除注释

    默认情况下,使用jd-gui反编译时会有注释. 行号注释 /* 521:502 */ 元信息 /* Location:           D:\core-1.0.0.jar * Qualified ...