【例题 7-5 UVA - 129】Krypton Factor
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
每次枚举增加一个字符;
然后看看新生成的字符的后缀里面有没有出现连续子串就好,前面已经确认过的没必要重复确认
(枚举长度为偶数的一个后缀就好)
是输出完第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的更多相关文章
- UVA.129 Krypton Factor (搜索+暴力)
UVA.129 Krypton Factor (搜索+暴力) 题意分析 搜索的策略是:优先找长串,若长串不合法,则回溯,继续找到合法串,直到找到所求合法串的编号,输出即可. 注意的地方就是合法串的判断 ...
- Uva 129 Krypton Factor
0.这道题的输出 处理起来挺麻烦的 以后类似的可以借鉴一下 ;i<cur;i++) { && i%==) printf("\n%c",a[i]); & ...
- UVa 129 Krypton Factor【回溯】
学习的紫书的回溯,理解起来还是好困难的说啊= = #include<iostream> #include<cstdio> #include<cstring> #in ...
- UVa 129 Krypton Factor困难的串 (dfs 递归搜索)
回溯法,只需要判断当前串的后缀,而不是所有的子串 #include<iostream> #include<cstdio> using namespace std; ]; int ...
- UVA - 129 Krypton Factor (困难的串)(回溯法)
题意:求由字母表前L个字母组成的字典序第n小的困难串.(如果一个字符串包含两个相邻的重复子串,则称它是"容易的串",其他串称为"困难的串".) 分析:回溯时,检 ...
- UVa 129 Krypton Factor (DFS && 回溯)
题意 : 如果一个字符串包含两个相邻的重复子串,则称它是“容易的串”,其他串称为“困难的 串”.例如,BB.ABCDACABCAB.ABCDABCD都是容易的串,而D.DC.ABDAB. CBABCB ...
- uva 129 krypton factors ——yhx
Krypton Factor You have been employed by the organisers of a Super Krypton Factor Contest in which ...
- 129 - Krypton Factor
/*UVa129 - Krypton Factor --回溯问题.看例子可知道确定该字符串是按照从左到右依次考虑每个位置,当前位置填不上所有的字符时,需要回溯. -- */ #define _CRT_ ...
- UVA 129_ Krypton Factor
题意: 一个字符串含有两个相邻的重复的子串,则称这个串为容易的串,其他为困难的串,对于给定n,l,求出由前l个字符组成的字典序第n小的困难的串. 分析: 按字典序在字符串末尾增加新的字符,并从当前字符 ...
- UVA129 Krypton Factor 困难的串 dfs回溯【DFS】
Krypton Factor Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
随机推荐
- 我在看着你呢——shiro学习
说实话开学第一周效率并不高.项目该结的都差不多结了,看来这毛病我是养成了.项目忙的要死的时候,想休息想停一停就不断往下扔包袱.一下没项目了开学了,反倒开始手痒,捉摸着写点什么代码.马上我的小mac就要 ...
- codeforces 140E.New Year Garland
传送门: 解题思路: 要求相邻两行小球颜色集合不同,并且限制行内小球相邻不同. 由此可得:每行小球排列都是独立与外界的, 所以答案应该是对于所有行的颜色集合分类,在将行内的答案乘到上面. 先考虑如何分 ...
- 学习推荐《Python神经网络编程》中文版PDF+英文版PDF+源代码
推荐非常适合入门神经网络编程的一本书<Python神经网络编程>,主要是三部分: 介绍神经网络的基本原理和知识:用Python写一个神经网络训练识别手写数字:对识别手写数字的程序的一些优化 ...
- C++ Primer高速入门之六:数组和指针
更新:勘误,delete [] 猪 我们知道,C语言以及早期的面向结构的语言差点儿都支持数组定义.比方整形数组int 女神[2].表示有俩数: 女神[0], 女神[1].她们都是整数. C++ 语言为 ...
- session timer(一)
功能介绍 SIP并没有为所建立的会话定义存活机制. 虽然用户代理能够通过会话特定的机制推断会话是否超时,可是代理server却做不到这点. 如此一来.代理server有时会无法推断会话是否还是活动的. ...
- Fragment-管理Fragment2
上一篇,给大家讲了有关Fragment管理的几个函数,即add,replace,remove,这节再讲讲其它函数,然后再给大家看一个系统BUG. 一.hide().show() 1.基本使用 这两个函 ...
- string StartsWith 方法 Https
public ActionResult Index() { string url = "Https://www.baodu.com"; ...
- 微信小程序---app.json中设置背景色不生效解决办法
按照官方文档的说明,backgroundColor应该可以设置窗口的背景色. "window":{ "backgroundTextStyle":"li ...
- 【hihocoder 1378】网络流二·最大流最小割定理
[Link]:http://hihocoder.com/problemset/problem/1378 [Description] [Solution] 在求完最小割(最大流)之后; 可以在剩余网络中 ...
- BASH 文本模版的简单实现 micro_template_compile
详细代码 ############################### # # Funciton: micro_template_compile # # Parameter: # [1] => ...