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

 #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. rpc 小例子

    RpcFramework /* * Copyright 2011 Alibaba.com All right reserved. This software is the * confidential ...

  2. org.eclipse.wst.common.project.facet.core.xml文件模板,解决eclipse编译报错。

    <?xml version="1.0" encoding="UTF-8"?> <faceted-project> <fixed f ...

  3. Sqli-labs less 32

    Less-32 利用上述的原理,我们可以进行尝试payload为: http://127.0.0.1/sqli-labs/Less-32/?id=-1%df%27union%20select%201, ...

  4. racle 11g impdp时 报ORA-12899

    racle 11g impdp时 报ORA-12899 (2012-07-16 16:42:12) 转载▼ 标签: oracle imp impdp it 分类: oracle技术-开发 源库ZHS1 ...

  5. LA 3350

    The NASA Space Center, Houston, is less than 200 miles from San Antonio, Texas (the site of the ACM ...

  6. iOS终端查看.a文件是否能在模拟器上运行

    复制文件路径进去: 红色框框里面没有x86所以模拟器运行会报错

  7. POJ 2080

    import java.util.*; public class Main { public static void main(String args[]){ Scanner cin=new Scan ...

  8. 深入浅出ES6(九):学习Babel和Broccoli,马上就用ES6

    作者 Jason Orendorff  github主页  https://github.com/jorendorff 现在,我们将向你分步展示如何做到的这一切.上面提及的工具被称为转译器,你可以将它 ...

  9. ExtJs之Ext.core.DomQuery

    <!DOCTYPE html> <html> <head> <title>ExtJs</title> <meta http-equiv ...

  10. poj 1062(有限制的最短路)

    题目链接:http://poj.org/problem?id=1062 思路:要求对于最短路上的点,不能出现等级之差大于m,于是我们可以枚举,假设酋长的等级为level,于是这个区间范围[level- ...