暴力求解

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

求字典序第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. if…else…if…else…

    参见以前做过的练习一元二次方程 #include <stdio.h> #include <math.h> /* 一元二次方程的标准形式:ax2+bx+c=0 a,b,c为常数, ...

  2. XMPP 服务器 Openfire 的 Emoji 支持问题(进行部分修改)

    当前最新版3.9.3已经可以支持Emoji  ----------------------------------------------------------------------------- ...

  3. 【转】OpenCV中使用神经网络 CvANN_MLP

    原文见:http://blog.csdn.net/xiaowei_cqu/article/details/9027617 OpenCV的ml模块实现了人工神经网络(Artificial Neural ...

  4. Vue.js介绍

    http://www.cnblogs.com/keepfool/p/5619070.html Vue.js介绍 Vue.js是当下很火的一个JavaScript MVVM库,它是以数据驱动和组件化的思 ...

  5. Krita 3.0 发布,KOffice 的图像处理器(刺激一下自己的神经)

    Krita 3.0 发布了,经历了一年多的开发,动画功能被集成到Krita核心,改善了绘画功能,可及时预览绘画结果,该版本也是最新移植到QT的版本. 查看完整发布说明,可以点击这里. 下载地址: Wi ...

  6. 基于visual Studio2013解决算法导论之045斐波那契堆

     题目 斐波那契堆 解决代码及点评 // 斐波那契堆.cpp : 定义控制台应用程序的入口点. // #include<iostream> #include<cstdio> ...

  7. “快的打车”创始人陈伟星的新项目招人啦,高薪急招Java服务端/Android/Ios 客户端研发工程师/ mysql DBA/ app市场推广专家,欢迎大家加入我们的团队! - V2EX

    "快的打车"创始人陈伟星的新项目招人啦,高薪急招Java服务端/Android/Ios 客户端研发工程师/ mysql DBA/ app市场推广专家,欢迎大家加入我们的团队! - ...

  8. Python标准库:内置函数repr(object)

    本函数是返回对象object的具体说明字符串. 样例: #repr() print(repr(range(5))) print(repr(help)) print(repr(0x200)) print ...

  9. c# winform 弹出确认消息框判断是否删除?

    if (MessageBox.Show("确认删除?", "此删除不可恢复", MessageBoxButtons.YesNo) == DialogResult ...

  10. SQL Server 基础 02 确保数据完整性

    本章总结目的:    为了巩固 约束.事务! 约 束 使用数据库约束就是保证数据库的完整性的方法,SQL Server 涉及的完整性有三个: 1.实体完整性 : (不能为空且重复,即唯一的,例如身份证 ...