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利用twilio模块给自己发短信

    1.访问http://twilio.com/并填写注册表单.注册了新账户后,你需要验证一个手机号码,短信将发给该号码. 2.Twilio 提供的试用账户包括一个电话号码,它将作为短信的发送者.你将需要 ...

  2. TOTP算法 基于时间的一次性密码

    /** Copyright (c) 2011 IETF Trust and the persons identified as authors of the code. All rights rese ...

  3. 山西某公司NetApp存储不小心删除文件数据恢复成功案例

    故障情况简介: 需要进行数据恢复的设备是一台NetApp存储,共有24块磁盘组成.由于管理员删除文件夹,且时间比较久,删除有几个月时间. 可恢复性判断:由于NetApp中的文件系统的特性,WAFL是& ...

  4. sql2008r2,以前好好可以用的,但装了vs2017后,连接不上了,服务也停了,结果手动也 启动不了, 无法加载或初始化请求的服务提供程

    日志: 2017-12-14 12:33:17.53 服务器 A self-generated certificate was successfully loaded for encryption.2 ...

  5. python全栈开发-logging模块(日记专用)

    一.概述 很多程序都有记录日志的需求,并且日志中包含的信息即有正常的程序访问日志,还可能有错误.警告等信息输出,python的logging模块提供了标准的日志接口,你可以通过它存储各种格式的日志,l ...

  6. BizTalk Server 2010高可用方案

    BizTalk Server 2010高可用方案 本文介绍了 Microsoft BizTalk Server 中通过对主机的各层进行扩展提供高可用性的方案. 分隔各个区域的功能分为不同的主机和中的层 ...

  7. emqtt 试用(二)验证 emq 和 mosquito 的共享订阅

    本地订阅(Local Subscription) 本地订阅(Local Subscription)只在本节点创建订阅与路由表,不会在集群节点间广播全局路由,非常适合物联网数据采集应用. 使用方式: 订 ...

  8. HTTP头HOST

    http request header 中的host行的作用 在早期的Http 1.0版中,Http 的request请求头中是不带host行的,在Http 1.0的加强版和Http 1.1中加入了h ...

  9. 深度理解DOM拷贝clone()

    克隆节点是DOM的常见操作,jQuery提供一个clone方法,专门用于处理dom的克隆: .clone()方法深度 复制所有匹配的元素集合,包括所有匹配元素.匹配元素的下级元素.文字节点. clon ...

  10. django Form组件 上传文件

    上传文件 注意:FORM表单提交文件要有一个参数enctype="multipart/form-data" 普通上传: urls: url(r'^f1/',views.f1), u ...