暴力求解

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

求字典序第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. USACO The Tamworth Two 模拟

    一道模拟题不过要担心的是牛或者人在转弯的时候,另一方如果能走,那么要走,不能停留. 还是蛮简单的. 调试输出的话可以看到具体追击过程 Source Code: /* ID: wushuai2 PROG ...

  2. (Problem 16)Power digit sum

    215 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26. What is the sum of the digits of th ...

  3. 言未及之而言,谓之躁;言及之而不言,谓之隐;未见颜色而言,谓之瞽(gǔ)

    前言 一个高效的团队离不开leader和组员之前,组员和组员之前的通力合作.而合作的基础便是彼此之间的商讨与协调,意见的统一,进而在达成共识的前提下行动.那么如何才能和组员达成共识呢? 和组员之间的沟 ...

  4. Linux环境下编译并执行ava helloworld程序

    原文:http://blog.lupaworld.com/home-space-uid-24466-do-blog-id-2578.html 已经学会怎样在Windows下怎样编辑,编译和运行Java ...

  5. 3DShader之投影贴图(Projective Texturing)

    相信大家都应该玩过CS或者CF吧,游戏里面有个喷图功能,就是按一个T键就能在墙上或者地板上喷出自己预先设定的图案. 而刚好这就是我们这个Shader所需实现的内容.由于没有潜伏者的贴图,我只有从这个图 ...

  6. Union - Find 、 Adjacency list 、 Topological sorting Template

    Find Function Optimization: After Path compression: int find(int x){ return root[x] == x ? x : (root ...

  7. 设计模式(二)单件模式Singleton(创建型)

    SINGLETON(单件)—对象创建型模式 几乎所有面向对象的程序中,总有一些类的对象需要是唯一的,例如,通过数据库句柄到数据库的连接是独占的.您希望在应用程序中共享数据库句柄,因为在保持连接打开或关 ...

  8. SAP超时问题

    其他常用的参数如下: login/system_client 登录时默认的Client号 login/password_expiration_time 密码有效期 login/fails_to_use ...

  9. Eclipse用法和技巧二十七:定义自己的快速联想词

    某天在调试代码的时候,虽然是android的project还是习惯的输入syso,然后在ALT+/一下.旁边的同事就问了一下,这个log打印输出的tag是什么.接着又问了为什么syso能够智能联想出这 ...

  10. ASIHTTPRequest-插件的使用

    链接地址:http://blog.sina.com.cn/s/blog_7b9d64af0101e5uf.html 一.什么是ASIHTTPRequest   ASIHTTPRequest 插件是一个 ...