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

 #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. Linux vi 中搜索关键字

    当你用vi打开一个文件后,因为文件太长,如何才能找到你所要查找的关键字呢? 在vi里可没有菜单-〉查找 不过没关系,可以在命令模式下敲斜杆( / )这时在状态栏(也就是屏幕左下脚)就出现了 “/” 然 ...

  2. wpf 制作播放视频的屏保程序、而且能分屏显示

    这个程序用到了WPF里  “visual_Brush”(主要是为了实现分屏显示) , “UserControl” ,这两个知识点: 在屏保状态下播放指定文件夹下的视频,而且能分屏显示: 把编译好的屏保 ...

  3. 《WPF程序设计指南》读书笔记——第1章 应用程序与窗口

    1.空白WPF项目的创建: 1)新建项目:在VS2010中,文件-新建-项目-visual c#-windows-空项目: 2)添加引用:PresentationFramework,Presentat ...

  4. 【信息学奥赛一本通】第三部分_队列 ex2_3produce 产生数

    给出一个整数n(n<=2000)(代码可适用n<=10^31)和k个变换规则(k<=15). 规则:1.1个数字可以变换成另1个数字: 2.规则中右边的数字不能为零. BFS #in ...

  5. Ducci Sequence

    Description   A Ducci sequence is a sequence of n-tuples of integers. Given an n-tuple of integers ( ...

  6. Asp.net之LINQ入门视频教程

    当前位置: 主页 > 编程开发 > Asp.net视频教程 > Asp.net之LINQ入门视频教程 > http://www.xin1234.com/Program/Aspn ...

  7. mybatis + postgresql 遇到的问题

    org.postgresql.util.PSQLException: ERROR: relation "circlefence" does not exist  这个问题是数据库表 ...

  8. mysql慢查询优化之explain的各列含义

    mysql> explain select customer_id,first_name,last_name from customer; +----+-------------+------- ...

  9. TWaver初学实战——如何在TWaver属性表中添加日历控件?

    在日期输入框中添加日历控件,是一种非常流行和实用的做法.临渊羡鱼不如退而写代码,今天就看看在TWaver中是如何实现的.   资源准备   TWaver的在线使用文档中,就有TWaver Proper ...

  10. MongoDB的C#驱动基本使用

    转载:http://www.cnblogs.com/wilber2013/p/4175825.html MongoDB的官方C#驱动可以通过 这个链接 得到.链接提供了.msi和.zip两种方式获取驱 ...