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 ( ...
随机推荐
- js switch表达式的例子
switch 这种表达式在很多语言中都有,比如java, C等待, 使用switch比使用if else 来得方便,来得清晰. 前言 switch 这种表达式在很多语言中都有,比如java, C等待 ...
- Python遍历文件夹枚举所有文件类型
>>> import os >>> def enumfiles(path, dest): files = os.listdir(path) for f in fil ...
- 三、mysql运算符
取模有2种方法: 或 mod(,) 比较一个字段的值是不是null有两种方法:is null 或 <=> null 不能直接使用 where id = null;是不对的
- IBM MQ
一,安装 1,先安装必备MQ\MQ60\Prereqs\IES\Setup.exe 2,再安装MQ\MQParms.exe 二,发送方 刚装好后,默认有一个管理器名,可以删除,自己重新建,以防有不可知 ...
- RedHat6.4 用UDEV配置ASM所需磁盘
同事在装一套RAC测试环境,结果发现原来用ASMLIB来配置磁盘,在安装GRID的时候,最终报错了,经过检查发现居然两边的磁盘不匹配.A机的sdb,sdc分别对应OCRVOL1,OCRVOL2,但是B ...
- 百度地图 获取矩形point
http://developer.baidu.com/map/jsdemo.htm#f0_7 鼠标绘制点线面 <!DOCTYPE html><html><head> ...
- CQRS学习——最小单元的Cqrs(CommandEvent)[其一]
[说明:博主采用边写边思考的方式完成这一系列的博客,所以代码以附件为准,文中代码仅为了说明.] 结构 在学习和实现CQRS的过程中,首要参考的项目是这个[http://www.cnblogs.com/ ...
- c#保留小数点后两位
double d = 23423.24234234d; Response.Write(d.ToString("0.00"));
- 团体程序设计天梯赛-练习集L2-007. 家庭房产
L2-007. 家庭房产 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 给定每个人的家庭成员和其自己名下的房产,请你统计出每个 ...
- windows下游戏服务器端框架Firefly安装说明及demo运行
原地址:http://blog.csdn.net/wangqiuyun/article/details/11150503 本来公司一个网游服务器端选定了pomelo框架,后来出了个Firefly,为做 ...