129 - Krypton Factor
/*UVa129 - Krypton Factor
--回溯问题。看例子可知道确定该字符串是按照从左到右依次考虑每个位置,当前位置填不上所有的字符时,需要回溯。
--
*/
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<fstream>
#include<time.h>
#include<vector>
using namespace std;
const int maxn = 1000; char ans[maxn];
int k, L, tol;
bool flag; bool isleg(int curr){
bool res = 1;
int i, b;
for (b = 0; b < curr; b++){
int len = curr - b + 1;
if (len & 1)continue;
for (i = 0; i < len / 2; i++){
if (ans[b+i] != ans[i + b + len / 2])break;
}
if (i == len / 2)res = 0;
if (!res)break;
}
return res;
}
void dfs(int curr){
if (tol==k){ //搜索到了解
for (int i = 0; i < curr; i++){
if (i&&i % 4 == 0){
if (i%64== 0)printf("\n");
else printf(" ");
}
printf("%c", ans[i]);
}
printf("\n%d\n",curr);
flag = 1;
return;
}
if (flag)return;
for (char i = 'A'; i < 'A' + L; i++){
ans[curr] = i;
if (isleg(curr)){
tol++; //合法解,tol++
dfs(curr + 1);
}
}
}
int main(){
while (scanf("%d%d", &k, &L) && k&&L){
flag = 0;
tol = 0;
dfs(0);
}
return 0;
}
129 - Krypton Factor的更多相关文章
- UVA.129 Krypton Factor (搜索+暴力)
UVA.129 Krypton Factor (搜索+暴力) 题意分析 搜索的策略是:优先找长串,若长串不合法,则回溯,继续找到合法串,直到找到所求合法串的编号,输出即可. 注意的地方就是合法串的判断 ...
- Uva 129 Krypton Factor
0.这道题的输出 处理起来挺麻烦的 以后类似的可以借鉴一下 ;i<cur;i++) { && i%==) printf("\n%c",a[i]); & ...
- UVa 129 Krypton Factor【回溯】
学习的紫书的回溯,理解起来还是好困难的说啊= = #include<iostream> #include<cstdio> #include<cstring> #in ...
- UVa 129 Krypton Factor困难的串 (dfs 递归搜索)
回溯法,只需要判断当前串的后缀,而不是所有的子串 #include<iostream> #include<cstdio> using namespace std; ]; int ...
- UVA - 129 Krypton Factor (困难的串)(回溯法)
题意:求由字母表前L个字母组成的字典序第n小的困难串.(如果一个字符串包含两个相邻的重复子串,则称它是"容易的串",其他串称为"困难的串".) 分析:回溯时,检 ...
- UVa 129 Krypton Factor (DFS && 回溯)
题意 : 如果一个字符串包含两个相邻的重复子串,则称它是“容易的串”,其他串称为“困难的 串”.例如,BB.ABCDACABCAB.ABCDABCD都是容易的串,而D.DC.ABDAB. CBABCB ...
- uva 129 krypton factors ——yhx
Krypton Factor You have been employed by the organisers of a Super Krypton Factor Contest in which ...
- Krypton Factor
Krypton Factor Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- UVA129 Krypton Factor 困难的串 dfs回溯【DFS】
Krypton Factor Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
随机推荐
- LINQ to Entities 不识别方法“System.Guid Parse(System.String)”,因此该方法无法转换为存储表达式。
LINQ to Entities 不识别方法"System.Guid Parse(System.String)",因此该方法无法转换为存储表达式. linq 中不能转换类型
- file mmap
do_set_pmd 统计参数只会在这里设置: add_mm_counter(vma->vm_mm, MM_FILEPAGES, HPAGE_PMD_NR); 但是这貌似都是处理大页的情况哪,小 ...
- ZOJ Bizarre Routine 2013杭州网赛B题
题目意思: 给定n, expect, a, b 要求你构造一组array[],存放一个1..n的排列,使的下面的程序能输出YES 题目所示代码: bool less_than(x, y) { T++; ...
- h5滚动条加载到底部
https://www.zhihu.com/question/31861301 重复加载问题 http://www.jianshu.com/p/12aa901bee1f?from=timeline w ...
- Ubuntu虚拟机编译Android6.0总结
1 前言 昨天使用清华的源下载了android 6.0的源码,校园网可以达到10M的速度,爽!今天一大早就迫不及待地准备编译一个模拟器版本,看看效果,哪知竟然耗费了一整天的时间才搞定...为了避免其他 ...
- mysql 逻辑架构(三层)
1.客户端(主要处理连接,授权认证,安全等). 2.MYSQL服务器层(核心服务功能都在这层,包括,查询解析,分析,优化,缓存以及所有的内置函数,所有跨存储引擎的功能都在这层实现:存储过程,触发器,视 ...
- HDU 5159 Card (概率求期望)
B - Card Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Sta ...
- Hoof, Paper, Scissors(USACO)
题目大意: 一种游戏(类似于石头剪刀布):两个人分别给出一个字母,然后比较:H>S,S>P,P>H,我们已知对手的字母顺序,求在前n局中我们最多能赢多少次. 由于出字母的人非常懒,所 ...
- andrio
## 以eclipse -clean命令从命令行启动 eclipse ## 配置Android模拟器 点击上图右边的按钮(像个手机一样的),打开AVD管理器后,点击 New 新建一个模拟器,输入Nam ...
- Linux系统调用--getrlimit()与setrlimit()函数详解【转】
转自:http://www.cnblogs.com/niocai/archive/2012/04/01/2428128.html 功能描述:获取或设定资源使用限制.每种资源都有相关的软硬限制,软限制是 ...