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

【题意】

在这里输入题意

【题解】

每次枚举增加一个字符;
然后看看新生成的字符的后缀里面有没有出现连续子串就好,前面已经确认过的没必要重复确认
(枚举长度为偶数的一个后缀就好)
是输出完第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. How Javascript works (Javascript工作原理) (十二) 网络层探秘及如何提高其性能和安全性

    个人总结:阅读完这篇文章需要20分钟,这篇文章主要讲解了现代浏览器在网络层传输所用到的一些技术, 应当对 window.performance.timing 这个API所有了解. 这是 JavaScr ...

  2. 【Henu ACM Round#17 D】Hexagons!

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 题目的图吓人. 找下规律就会发现从内到外是1,6,12,18 即1,16,26,36... 即1+6(1+2+3+...) 等差求和 ...

  3. thinkphp3.2.3 隐藏url上home模块以及index.php文件

    1.去掉Home index.php 添加如下代码 define('BIND_MODULE', 'Home'); 这时就隐藏了url中的Home 2.去掉index.php thinkphp3.2.3 ...

  4. Your Ruby version is 2.2.3, but your Gemfile specified 2.2.2

    在文章 Ruby On Rails中REST API使用演示样例--基于云平台+云服务打造自己的在线翻译工具 中,从Bluemix上下载的初始Hello World演示样例代码在本地环境下运行调试时提 ...

  5. HDOJ 4460 Friend Chains 图的最长路

    类似于树的直径,从随意一个点出发,找到距离该点最远的且度数最少的点. 然后再做一次最短路 Friend Chains Time Limit: 2000/1000 MS (Java/Others)    ...

  6. Java 位运算符 深入理解

    在Java中存在着这样一类操作符,是针对二进制进行操作的.它们各自是&.|.^.~.>>.<<.>>>几个位操作符.不管是初始值是依照何种进制,都会换 ...

  7. js---16继承

    123 instanceof Number;//false,要左边是对象右边是函数 typeof 123 ; //number new Number(123) instanceof Number; / ...

  8. js02---字符串

    <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...

  9. C#接口,类,集成

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  10. js实现删除确认提示框

    js实现删除确认提示框 一.实例描述 防止用户小心单击了“删除”按钮,在用户单击“删除”按钮后,给出一个提示,让用户确认此次操作是否正确. 二.效果 三.代码 <!DOCTYPE html> ...