暴力求解

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

求字典序第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. Qt对话框_模态/非模态

    对话框在Qt GUI应用程序中有着广泛的用途,对话框有模态.非模态两种情况. 对于参数选择的对话框,一般用模态对话框:对于显示或查看某些内容的对话框,一般用非模态对话框. 对话框类QDialog,官方 ...

  2. Clojure学习05:谓词函数

    谓词函数是一个判断式,一个返回bool值的函数. clojure中(lisp习惯)有个规定:对于判断功能的函数,函数名后面都有一个“?”号.所以只要看到后面带问号的函数名,就知道这一定是一个判断函数. ...

  3. ZooKeeper原理及配置

    ooKeeper实验版本:3.4.6 ZooKeeper下载地址:http://www.apache.org/dyn/closer.cgi/zookeeper/ zookeeper是一个高可用性,高性 ...

  4. 基于visual Studio2013解决算法导论之023队列实现(基于数组)

     题目 基于数组的队列 解决代码及点评 #include <stdio.h> #include <stdlib.h> #include <time.h> #i ...

  5. 基于visual Studio2013解决C语言竞赛题之0515国名排序

     题目

  6. make报错:"/usr/bin/ld: cannot find -lXXX"

    在编译php时报错如下: # make ... /usr/bin/ld: cannot find -lltdlcollect2: ld returned 1 exit statusmake: *** ...

  7. 蓝牙Profile的概念和常见种类

    蓝牙Profile Bluetooth的一个很重要特性,就是所有的Bluetooth产品都无须实现全部 的Bluetooth规范.为了更容易的保持Bluetooth设备之间的兼容,Bluetooth规 ...

  8. hdu 4940 Destroy Transportation system( 无源汇上下界网络流的可行流推断 )

    题意:有n个点和m条有向边构成的网络.每条边有两个花费: d:毁坏这条边的花费 b:重建一条双向边的花费 寻找这样两个点集,使得点集s到点集t满足 毁坏全部S到T的路径的费用和 > 毁坏全部T到 ...

  9. PHP - 图像处理

    第14章 处理图像 学习要点: 1.创建图像 2.简单小案例 在PHP5中,动态图象的处理要比以前容易得多.PHP5在php.ini文件中包含了GD扩展包,只需去掉GD扩展包的相应注释就可以正常使用了 ...

  10. 时间运算函数 CATT_ADD_TO_TIME