暴力求解

大致题意 如果一个字符串含有相邻的重复字串称为容易的串,反之为非容易

求字典序第n困难的串……

大致思路,暴力如果是容易的串停过,然后困难的串继续求解tot++

总之先记着吧……

最后输出格式……

uva 129

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <stack>
#include <cctype>
#include <string>
#include <malloc.h>
#include <queue>
#include <map> using namespace std;
const int INF = 0xffffff;
const double esp = 10e-;
const double Pi = * atan(1.0);
const int Maxn = + ;
const int mod = ;
const int dr[] = {,,-,,-,,-,};
const int dc[] = {,,,-,,-,-,};
//int dir2[8][2] = {{-1,0},{0,-1},{-1,1},{1,-1},{-1,-1},{1,0},{0,1},{1,1}}; int n,L;
int a[];
int tot; bool dfs(int cur){
if(tot++ == n){
for(int i = ;i < cur;i++){
if(i && i % == ){
if(i % (*) == ){
cout << endl;
//cout << "$$$$";
}
else
cout << ' ';
}
cout << char(a[i] + 'A');
}
cout << endl;
cout << cur << endl;
return ;
}
for(int i = ;i < L;i++){
a[cur] = i;
bool ok = ;
for(int j = ;j * < cur+;j++){
bool flag = ;
for(int k = ;k < j;k++){
if(a[cur-k] != a[cur-k-j]){
flag = ;
break;
}
}
if(flag){
ok = ;
break;
}
}
if(ok){
if(!dfs(cur+)){
return ;
}
}
}
return ;
} int main()
{
#ifndef ONLINE_JUDGE
freopen("inpt.txt","r",stdin);
#endif
while(cin >> n >> L){
if(!n && !L)
break;
tot = ;
dfs();
}
return ;
}

回家一直在玩,好难过……!!!!

以后要加油……!!!

uva 129的更多相关文章

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

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

  2. Krypton Factor 困难的串-Uva 129(回溯)

    原题:https://uva.onlinejudge.org/external/1/129.pdf 按照字典顺序生成第n个“困难的串” “困难的串”指的是形如ABAB, ABCABC, CDFGZEF ...

  3. UVa 129 困难的串

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  4. uva 129 krypton factors ——yhx

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

  5. Uva 129 Krypton Factor

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

  6. UVa 129 Krypton Factor【回溯】

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

  7. UVa 129 (回溯法) Krypton Factor

    回溯法确实不是很好理解掌握的,学习紫书的代码细细体会. #include <cstdio> ]; int n, L, cnt; int dfs(int cur) { if(cnt++ == ...

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

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

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

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

随机推荐

  1. Kruscal 、 Prime Template

    Kruscal  Template : 很裸的Kruscal Template(求最小生成树中最长路,即最短路中最长路) //#pragma comment(linker, "/STACK: ...

  2. Dreamweaver显示花括号匹配

    按Ctrl+' 可以显示对应括号内的代码.dreamweaver没办法高亮显示花括号.而且没有块选择功能.个人认为Dreamweaver的编辑功能很糟糕.

  3. hdu 2757 Ocean Currents(优先队列+bfs)

    小伙伴们真心被这道题惊呆了!刚开始是读题,题目都把小伙伴惊呆了,题目都读不懂! 在前面猴子小伙伴的帮助下,理解了一点点,又偷偷的在纸上写写画画,明白了题意! 后来,你懂的,果断拿下!在拿下的过程也经过 ...

  4. Linux命令之find(一)

    find命令的使用格式为:find options path expressions find命令事实上有两种options,一种是"真正属于自己的",还有一种位于expressi ...

  5. Android中的单元测试

    2015年5月19日 23:10     在Android中,已经内置了Junit所以不需要在导包.只要继承AndroidTestCase类就可以了.     首先需要修改AndroidManifes ...

  6. android软键盘弹出隐藏的监听

    通过网上搜索关于软键盘的隐藏弹出的监听,有几种方式,其中最有效的方式是在View的Onlayout()里面做文章 具体代码: 将布局视图自定义,重写onlayout()方法,然后在主Activity里 ...

  7. 不能使用ASP.NET验证控件---WebForms UnobtrusiveValidationMode 需要“jquery”ScriptResourceMapping。请添加一个名为 jquery (区分大小写)的 ScriptRes

    方法一: 在webconfig中找到 <appSettings>        <add key=" aspnet:UseTaskFriendlySynchronizati ...

  8. BZOJ 2427: [HAOI2010]软件安装( dp )

    软件构成了一些树和一些环, 对于环我们要不不选, 要么选整个环. 跑tarjan缩点后, 新建个root, 往每个入度为0的点(强连通分量) 连边, 然后跑树dp( 01背包 ) ---------- ...

  9. java--继承的一些笔记

    public class Person { public void display(){ System.out.println("Play Person..."); } stati ...

  10. JVM调优总结(八)-典型配置举例2

    常见配置汇总 堆设置 -Xms:初始堆大小 -Xmx:最大堆大小 -XX:NewSize=n:设置年轻代大小 -XX:NewRatio=n:设置年轻代和年老代的比值.如:为3,表示年轻代与年老代比值为 ...