【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

每次枚举增加一个字符;
然后看看新生成的字符的后缀里面有没有出现连续子串就好,前面已经确认过的没必要重复确认
(枚举长度为偶数的一个后缀就好)
是输出完第64组且保证有第65组才要输出一个换行.

【代码】

import java.io.*;
import java.util.*;
public class Main{
static int n,l,cnt;
static int a[] = new int[1000];
static ArrayList<Integer> list = new ArrayList<Integer>(); static int dfs(int now){
if (now > 1){
cnt++;
if (cnt==n){
for (int i = 1;i < now;i++) list.add(a[i]);
return 0;
}
}
for (int i = 1;i <= l;i++){
a[now] = i;
boolean ok = true;
for (int j = 1; now-2*j+1>=1;j++){
boolean ju = true;
for (int k = now-j+1;k<=now;k++){
if (a[k]!=a[k-j]){
ju = false;
break;
}
}
if (ju==true){
ok = false;
break;
}
}
if (!ok) continue;
if (dfs(now+1)==0) return 0;
}
return 1;
} public static void main(String args[]){
Scanner cin = new Scanner(System.in);
while (cin.hasNext()){
n = cin.nextInt();l = cin.nextInt();
if (n==0 && l==0) break;
cnt = 0;
list.clear();
dfs(1);
int tot = list.size();
for (int i = 0;i < tot;i++){
if (i%4==0 && i >0) {
if (i % 64 == 0) {
System.out.println("");
} else {
System.out.print(' ');
}
}
System.out.print((char)(list.get(i)+'A'-1));
}
System.out.println("");
System.out.println(tot);
}
}
}

【例题 7-5 UVA - 129】Krypton Factor的更多相关文章

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

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

  2. Uva 129 Krypton Factor

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

  3. UVa 129 Krypton Factor【回溯】

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

  4. UVa 129 Krypton Factor困难的串 (dfs 递归搜索)

    回溯法,只需要判断当前串的后缀,而不是所有的子串 #include<iostream> #include<cstdio> using namespace std; ]; int ...

  5. UVA - 129 Krypton Factor (困难的串)(回溯法)

    题意:求由字母表前L个字母组成的字典序第n小的困难串.(如果一个字符串包含两个相邻的重复子串,则称它是"容易的串",其他串称为"困难的串".) 分析:回溯时,检 ...

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

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

  7. uva 129 krypton factors ——yhx

     Krypton Factor  You have been employed by the organisers of a Super Krypton Factor Contest in which ...

  8. 129 - Krypton Factor

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

  9. UVA 129_ Krypton Factor

    题意: 一个字符串含有两个相邻的重复的子串,则称这个串为容易的串,其他为困难的串,对于给定n,l,求出由前l个字符组成的字典序第n小的困难的串. 分析: 按字典序在字符串末尾增加新的字符,并从当前字符 ...

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

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

随机推荐

  1. Chromium String usage

    For Developers‎ > ‎ Chromium String usage Types of StringsIn the Chromium code base, we use std:: ...

  2. Ubuntu16.04安装官方Firefox 火狐浏览器 延长支持版(Extended Support Release, 简称“ESR”)

    Ubuntu16.04安装官方Firefox 火狐浏览器 延长支持版(Extended Support Release, 简称“ESR”) 延长支持版本(Extended Support Releas ...

  3. caioj 1066 动态规划入门(一维一边推4:护卫队)(分组型dp总结)

    很容易想到f[i]为前i项的最优价值,但是我一直在纠结如果重量满了该怎么办. 正解有点枚举的味道. 就是枚举当前这辆车与这辆车以前的组合一组,在能组的里面取最优的. 然后要记得初始化,因为有min,所 ...

  4. Zookeeper vs. etcd

    etcd是go语言实现的. 对比,可以参考这篇文章: http://studygolang.com/articles/4837 <服务发现:Zookeeper vs etcd vs Consul ...

  5. Linux下Oracle的sqlplus中上下左右退格键无法使用

    一.配置yum源并安装readline* 配置本地yum 1.挂载光盘 mount /dev/cdrom /mnt/media 2,新建本地yun源的配置文件 vi /etc/yum.repos.d/ ...

  6. Android 计算Bitmap大小

    今天使用LruCache写demo的时候,要获取Bitmap的大小 于是就用到了 return bitmap.getRowBytes() * bitmap.getHeight();// 获取大小并返回 ...

  7. POJ 2459 模拟

    题意: 思路: 按照题意模拟即可 //By SiriusRen #include <cstdio> using namespace std; int c,f1,f2,d,xx,yy,vis ...

  8. Lucene 定义

    福利 => 每天都推送 欢迎大家,关注微信扫码并加入我的4个微信公众号:   大数据躺过的坑      Java从入门到架构师      人工智能躺过的坑         Java全栈大联盟   ...

  9. spring源码分析之@Conditional

    根源在AnnotationConfigApplicationContext和AnnotationConfigWebApplicationContext,以AnnotationConfigApplica ...

  10. zhizhang错误(每天更新更新)

    做题反思(Think twice ,Code once) 1.2013NOIP转圈游戏,交代码前一定要静态查错,看看代码写得和自己意思一不一样,竟然把变量n写成了常数10,低级错误 2.2013NOI ...