UVa 129 (回溯法) Krypton Factor
回溯法确实不是很好理解掌握的,学习紫书的代码细细体会。
#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的更多相关文章
- Krypton Factor 困难的串-Uva 129(回溯)
原题:https://uva.onlinejudge.org/external/1/129.pdf 按照字典顺序生成第n个“困难的串” “困难的串”指的是形如ABAB, ABCABC, CDFGZEF ...
- UVA.129 Krypton Factor (搜索+暴力)
UVA.129 Krypton Factor (搜索+暴力) 题意分析 搜索的策略是:优先找长串,若长串不合法,则回溯,继续找到合法串,直到找到所求合法串的编号,输出即可. 注意的地方就是合法串的判断 ...
- UVa 129 Krypton Factor困难的串 (dfs 递归搜索)
回溯法,只需要判断当前串的后缀,而不是所有的子串 #include<iostream> #include<cstdio> using namespace std; ]; int ...
- UVA129 Krypton Factor 困难的串 dfs回溯【DFS】
Krypton Factor Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- uva 129 krypton factors ——yhx
Krypton Factor You have been employed by the organisers of a Super Krypton Factor Contest in which ...
- UVA - 524 Prime Ring Problem(dfs回溯法)
UVA - 524 Prime Ring Problem Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & % ...
- 129 - Krypton Factor
/*UVa129 - Krypton Factor --回溯问题.看例子可知道确定该字符串是按照从左到右依次考虑每个位置,当前位置填不上所有的字符时,需要回溯. -- */ #define _CRT_ ...
- UVA - 524 Prime Ring Problem(素数环)(回溯法)
题意:输入n,把1~n组成个环,相邻两个数之和为素数. 分析:回溯法. #pragma comment(linker, "/STACK:102400000, 102400000") ...
- 【LeetCode】回溯法 backtracking(共39题)
[10]Regular Expression Matching [17]Letter Combinations of a Phone Number [22]Generate Parentheses ( ...
随机推荐
- php中类的声明与使用
<?php /**php语言是支持面向对象编程的,对于面向对象的编程,学过java和C++的人都知道啊! *如果不清楚的去baidu问一下就可以了. */ //我们来定义一个类,定义类的关键字是 ...
- 如何在eclipse中配置Selenium
1, Install python 33.(Python 27也可以) 2, Setup Selenium If you did not install Easy_install module, yo ...
- zhuan:windows用一键安装包安装(推荐)-禅道
访问地址:http://www.zentao.net/book/zentaopmshelp/76.html 一键安装包 解压缩必须 解压缩到根目录下面.
- 关于帝国cms 列表页SEO优化的问题
一般列表页面中,我们都需要带分页信息区分当前页号,为区分第一页,和第一页后的其他所有分页页面.我们推荐的做法为:第一页显示正常的标题,从第二页开始便显示xxxxx-第2页-xxxx网.做法是.修改帝国 ...
- 《ENVI下遥感影像自然真彩色合成方法》——TM、spot5
来源:http://blog.sina.com.cn/s/blog_764b1e9d0100tz4f.html#bsh-73-375271630
- iOS 的UINavigationController详解与使用添加UIBarButtonItem
转发自:http://blog.csdn.net/totogo2010/article/details/7681879 分类: iOS开发入门2012-06-21 11:10 53077人阅读 评论( ...
- MyEcpilise引入Maven项目目录不正常,无JRE,无Maven Dependencies
右键项目--> Maven4MyEclipse --> Update Project Configuration
- 操作邮箱的类和文件的Md5【粘】
MailMessage mailMsg = new MailMessage();//两个类,别混了,要引入System.Net这个Assembly mailMsg.From ...
- Contest2037 - CSU Monthly 2013 Oct (problem D :CX and girls)
[题解]: 最短路径问题,保证距离最短的同时,学妹权值最大,哈哈 [code]: #include<iostream> #include<queue> #include< ...
- Hybrid App 和 React Native 开发那点事
简介:Hybrid App(混合模式移动应用)开发是指介于Web-app.Native-App这两者之间的一种开发模式,兼具「Native App 良好用户交互体验的优势」和「Web App 跨平台开 ...