Input and Output

In order to provide the Quiz Master with a potentially unlimited source of questions you are asked to write a program that will read input lines that contain integers n and L (in that order), where n > 0 and L is in the range  , and for each input line prints out the nth hard sequence (composed of letters drawn from the first L letters in the alphabet), in increasing alphabetical order (alphabetical ordering here corresponds to the normal ordering encountered in a dictionary), followed (on the next line) by the length of that sequence. The first sequence in this ordering is A. You may assume that for given n and L there do exist at least n hard sequences.

For example, with L = 3, the first 7 hard sequences are:


AB 
ABA 
ABAC 
ABACA 
ABACAB 
ABACABA

As each sequence is potentially very long, split it into groups of four (4) characters separated by a space. If there are more than 16 such groups, please start a new line for the 17th group.

Therefore, if the integers 7 and 3 appear on an input line, the output lines produced should be

ABAC ABA
7

Input is terminated by a line containing two zeroes. Your program may assume a maximum sequence length of 80.

Sample Input

30 3
0 0

Sample Output

ABAC ABCA CBAB CABA CABC ACBA CABA
28

题意:如果有一个字符串中包含两个相邻的重复子串,则称作容易的串,其他的则称为困难的串,要求不包含容易的串

#include <iostream>
#include <cstdio>
#include <vector>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
int cnt ;
char ma[1100][1100];
int n, len;
int p[100];
int dfs(int cur)
{
if(cnt == n)
{
for(int i = 1; i < cur; i++)
{
printf("%c",p[i] + 'A' -1);
if(i == cur - 1)
break;
if(i%4==0)
{
if(i%64==0)
putchar('\n');
else
putchar(' ');
}
}
printf("\n%d\n", cur-1);
return 0;
}
for(int i = 1; i <= len; i++)
{
p[cur] = i;
int ok = 1;
for(int j = 1; j * 2 <= cur+1; j++) //枚举进行比较
{
int flag =1;
for(int k = 0; k < j; k++)
{
if(p[cur- k] != p[cur-j-k])
{
flag = 0;
break;
}
}
if(flag )
{
ok =0;
break;
}
}
if(ok)
{
cnt ++;
if(!dfs(cur + 1))
return 0;
}
}
return 1;
} int main()
{
while(scanf("%d%d",&n,&len) != EOF)
{
cnt = 0;
if(!n && !len)
break;
dfs(1);
}
return 0;
}

  

UVA129 —— Krypton Factor (氪因素)的更多相关文章

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

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

  2. uva129 - Krypton Factor 7.4.3 困难的串

      7.4.3困难的串 学习点:dfs加入返回值,递归搜索过程中如果有一个成功,就直接退出 //7.4.3 困难的串 #include<cstdio> #include<cstrin ...

  3. 129 - Krypton Factor

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

  4. Krypton Factor

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

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

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

  6. UVa 129 Krypton Factor (DFS && 回溯)

    题意 : 如果一个字符串包含两个相邻的重复子串,则称它是“容易的串”,其他串称为“困难的 串”.例如,BB.ABCDACABCAB.ABCDABCD都是容易的串,而D.DC.ABDAB. CBABCB ...

  7. Uva 129 Krypton Factor

    0.这道题的输出 处理起来挺麻烦的 以后类似的可以借鉴一下 ;i<cur;i++) { && i%==) printf("\n%c",a[i]); & ...

  8. UVa 129 Krypton Factor【回溯】

    学习的紫书的回溯,理解起来还是好困难的说啊= = #include<iostream> #include<cstdio> #include<cstring> #in ...

  9. UVa 129 (回溯法) Krypton Factor

    回溯法确实不是很好理解掌握的,学习紫书的代码细细体会. #include <cstdio> ]; int n, L, cnt; int dfs(int cur) { if(cnt++ == ...

随机推荐

  1. python的Collections 模块

    Collections 模块 知识点 Counter 类 defaultdict 类 namedtuple 类 在这个实验我们会学习 Collections 模块.这个模块实现了一些很好的数据结构,它 ...

  2. 消除ExtJS6的extjs-trila字样

  3. JAVA_SE基础——25.面向对象练习

    黑马程序员入学blog ... 昨晚我写了篇面向对象的内存分析,今天我们来做个小练习.. 需求: 使用java描述一个车与修车厂两个事物, 车具备的公共属性:轮子数. 名字. 颜色 ,还 具备跑的功能 ...

  4. iot前台开发环境:前后台访问映射

    一.前端映射- java代码 二.路由设置 -前台代码 三.访问应用

  5. OAuth2.0学习(1-12)开源的OAuth2.0项目和比较

    OAuth2.0学习(2-1)OAuth的开源项目   1.开源项目列表 http://www.oschina.net/project/tag/307/oauth?lang=19&sort=t ...

  6. Spring Security 入门(3-11)Spring Security 的使用-自定义登录验证和回调地址

    配置文件 security-ns.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmln ...

  7. JS解析JSON字符串

    问题描述:后台需要传递给前台一些数据,用于页面数据显示,因为是一些Lable标签,所以数据传递到前台需要解析. 思路:因为数据比较杂乱,所以我选择传递的数据类型是Json格式,但是数据展示时需要解析成 ...

  8. flash上传文件,如何解决跨域问题

    今天同事遇到一个问题,我们有两个应用,一个后台应用,主要用于运营人员编辑文章,发布到官网:一个图片服务器应用,其他很多的应用上传的图片也会存放在这,还对外提供一些查询和管理api. 前者部署在back ...

  9. SendMessage 遇到的神坑

    场景 两个进程A和B,需要从A中设置B中的文本框的内容 过程 x.x.x.x. 成功获取了B中的内容,惊喜,离成功更近异步 xxxx ***** ....... x.x.x.x. 大约查找了几百个网页 ...

  10. Spark:reduceByKey函数的用法

    reduceByKey函数API: def reduceByKey(partitioner: Partitioner, func: JFunction2[V, V, V]): JavaPairRDD[ ...