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. 20162328蔡文琛week06

    学号 2016-2017-2 <程序设计与数据结构>第X周学习总结 教材学习内容总结 继承是从已有类派生出一个新类的过程. 继承的目的之一之复用已有的软件. 继承呢在子类和父类见建立了is ...

  2. idea 导eclipse项目

    https://www.cnblogs.com/xiaoBlog2016/archive/2017/05/08/6825014.html

  3. 数据恢复案例分享:MSSQL 2000 错误823

    一.故障描述 MSSQL Server 2000 附加数据库错误823,附加数据库失败.数据库没有备份,不能通过备份恢复数据库,急需恢复数据库中的数据. 二.故障分析SQL Server数据库 823 ...

  4. Python之旅.第三章.函数3.29

    一.无参装饰器 1 开放封闭原则 软件一旦上线后,就应该遵循开放封闭原则,即对修改源代码是封闭的,对功能的扩展是开放的 也就是说我们必须找到一种解决方案: 能够在不修改一个功能源代码以及调用方式的前提 ...

  5. Clover3(可以让Windows Explorer像浏览器一样有标签页)

    这不是广告!!! 下载地址:http://cn.ejie.me/ 效果图:

  6. python-map的用法

    map()函数 map()是 Python 内置的高阶函数,它接收一个函数 f 和一个 list,并通过把函数 f 依次作用在 list 的每个元素上,得到一个新的 list 并返回. 1.当seq只 ...

  7. SpringBoot入门:新一代Java模板引擎Thymeleaf(实践)

    菜鸟教程:http://www.runoob.com/ http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js http://apps.b ...

  8. java基础总结(1)安装jdk

           卸载java java -version yum remove java yum groupjava java        安装java tar -zxvf jdk-8u60-linu ...

  9. 一个适用于单页应用,返回原始滚动条位置的demo

    如题,最近做一个项目时,由于页面太长,跳转后在返回又回到初始位置,不利于用户体验,需要每次返回到用户离开该页面是的位置.由于是移动端项目,使用了移动端的套ui框架framework7,本身框架的机制是 ...

  10. java专业术语

    java的(PO,VO,TO,BO,DAO,POJO)解释 PO(persistant object) 持久对象 在o/r映射的时候出现的概念,如果没有o/r映射,没有这个概念存在了.通常对应数据模型 ...