【例题 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 ...
随机推荐
- nodeType 节点的类型
元素结点 1 属性结点 2 attributes 文本结点 3 注释结点 8 document结点 9 documentFragment 11 文档碎片
- 紫书 例题 9-14 UVa 1218 (树形dp)
这道题有个初始值设成1e9, 然后这个值是要加很多次的,然后就会溢出变成负数, 然后就一直WA, 找这个bug找了一个小时--以后不能随便这样设那么大, 要考虑会不会加很多次然后溢出. 讲一下思路. ...
- 今日SGU 5.16
SGU 119 题意:给你N.A0.B0,然后问所有X.Y,若A0X+B0Y能被N整除,则AX+BY也能被N整除,求所有的A.B.(0<=A.B<N) 收获:枚举 因为a0x+b0y=k1 ...
- CodeForcesGym 100502E Opening Ceremony
Opening Ceremony Time Limit: 5000ms Memory Limit: 524288KB This problem will be judged on CodeForces ...
- javaWeb自己定义可排序过滤器注解,解决Servlet3.0下@WebFilter注解无法排序问题
com.lwl.anno 凝视类型 @WebFilterSort 须要用的jar包 http://download.csdn.net/detail/u013202238/9431110 用该注解注冊的 ...
- 空间矢量数据(.shp文件)之JAVA操作
Shape文件由ESRI开发.一个ESRI(Environmental Systems Research Institute)的shape文件包含一个主文件,一个索引文件,和一个dBASE表. 当中主 ...
- OpenCASCADE Face Normals
OpenCASCADE Face Normals eryar@163.com Abstract. 要显示一个逼真的三维模型,其顶点坐标.顶点法向.纹理坐标这三个信息必不可少.本文主要介绍如何在Open ...
- gvim window7 下提示乱码
今天在win7下安装gvim的时候,发现所有的提示信息都是乱码的,在网上找到了如下的解决方案.在此记录下,方便以后查阅. 以下内容转载自http://blog.csdn.net/rehung/arch ...
- 适合ASP.NET Web API使用的场景
富客户端web应用程序:ASP.NET Web API适合大量使用AJAX调用的富客户端应用程序,如Silverlight应用程序,基于Adobe Flash的应用程序或单页应用程序(SPA)等. 本 ...
- javafx Cursor
public class EffectTest extends Application { ObservableList cursors = FXCollections.observableArray ...