回溯法确实不是很好理解掌握的,学习紫书的代码细细体会。

 #include <cstdio>

 char S[];
int n, L, cnt; int dfs(int cur)
{
if(cnt++ == n)
{
for(int i = ; i < cur; ++i)
{
if(i % == && i) puts("");
else if(i % == && i) printf(" ");
printf("%c", 'A' + S[i]);
}
printf("\n%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) == && n)
{
cnt = ;
dfs();
} return ;
}

代码君

UVa 129 (回溯法) Krypton Factor的更多相关文章

  1. Krypton Factor 困难的串-Uva 129(回溯)

    原题:https://uva.onlinejudge.org/external/1/129.pdf 按照字典顺序生成第n个“困难的串” “困难的串”指的是形如ABAB, ABCABC, CDFGZEF ...

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

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

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

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

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

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

  5. uva 129 krypton factors ——yhx

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

  6. UVA - 524 Prime Ring Problem(dfs回溯法)

    UVA - 524 Prime Ring Problem Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & % ...

  7. 129 - Krypton Factor

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

  8. UVA - 524 Prime Ring Problem(素数环)(回溯法)

    题意:输入n,把1~n组成个环,相邻两个数之和为素数. 分析:回溯法. #pragma comment(linker, "/STACK:102400000, 102400000") ...

  9. 【LeetCode】回溯法 backtracking(共39题)

    [10]Regular Expression Matching [17]Letter Combinations of a Phone Number [22]Generate Parentheses ( ...

随机推荐

  1. Spark Streaming揭秘 Day6 关于SparkStreaming Job的一些思考

    Spark Streaming揭秘 Day6 关于SparkStreaming Job的一些思考 Job是SparkStreaming的重要基础,今天让我们深入,进行一些思考. Job是什么? 首先, ...

  2. 爬虫学习之基于Scrapy的网络爬虫

    ###概述 在上一篇文章<爬虫学习之一个简单的网络爬虫>中我们对爬虫的概念有了一个初步的认识,并且通过Python的一些第三方库很方便的提取了我们想要的内容,但是通常面对工作当作复杂的需求 ...

  3. gc overhead limit exceeded

    eclipse-- gc overhead limit exceeded 修改内存不足的方法如下: Eclipse报错:gc overhead limit exceeded eclipse 原因是Ec ...

  4. XML文件序列化和反序列化的相关内容

    问题缘由: XML反序列化出错,XML 文档(2, 2)中有错误,不应有 <configuration xmlns=''> 解决方法: 其实这个是很简单的,因为一般来说都是XML文档书写错 ...

  5. jQuery ajax 实现分页 kkpager插件

    代码片段一: <!--分页组件 JS CSS 开始--> <!--分页组件 CSS--> <link type="text/css" href=&qu ...

  6. 洛谷 P1858 多人背包

    求01背包前k优解的价值和 输入输出格式 Input/output 输入格式:第一行三个数K.V.N(k<=50,v<=5000,n<=200)接下来每行两个数,表示体积和价值输出格 ...

  7. parsing html in asp.net

    http://stackoverflow.com/questions/5307374/parsing-html-page-in-asp-net http://htmlagilitypack.codep ...

  8. csu 1303 Decimal (数论题)

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1303 1303: Decimal Time Limit: 1 Sec  Memory Limit: ...

  9. NSFileHandle 和 NSFileManager的一些用法

    文件操作 NSFileManager 常见的NSFileManager文件的方法: -(BOOL)contentsAtPath:path 从文件中读取数据 -(BOOL)createFileAtPat ...

  10. jq获取元素到底部的距离

    // var wh = $(window).height(),//是文档窗口高度 // ot = $("#icoimg").offset().top,//是标签距离顶部高度 // ...