例题7-5 困难的串(Krypton Factor, UVa 129)
来源:互联网 发布:数据备份软件下载 编辑:程序博客网 时间:2024/05/22 01:27
这题乍一看好像是子集生成诶。。
主要问题就在于没添加一个字符后判断是否有连续相同子串。。
由于对每个串而言,所有的前缀都是已经判断过无相同的。。所以只需要判断后缀即可。
主要问题就在于没添加一个字符后判断是否有连续相同子串。。
由于对每个串而言,所有的前缀都是已经判断过无相同的。。所以只需要判断后缀即可。
#include <iostream>#include <string>#include <vector>#include <stack>#include <queue>#include <deque>#include <set>#include <map>#include <algorithm>#include <sstream>#include <utility>#include <cstring>#include <cstdio>#include <cstdlib>#include <ctime>#include <cmath>#include <cctype>#define CLEAR(a, b) memset(a, b, sizeof(a))#define IN() freopen("in.txt", "r", stdin)#define OUT() freopen("out.txt", "w", stdout)#define LL long long#define maxn 105#define maxm 10005#define mod 1000000007#define INF 1000000007#define eps 1e-5#define PI 3.1415926535898#define N 52using namespace std;//-------------------------CHC------------------------------//int L, n, cnt;char a[maxn];bool check(int cur, int c) {char ch = 'A' + c;for (int i = 1; i <= (cur + 1) >> 1; ++i) {bool same = true;for (int j = 0; j < i; ++j) {if (a[cur - j] != a[cur - i - j]) same = false;}if (same) return false;}return true;}bool dfs(int cur) {if (cnt == n) {for (int i = 0; i < cur; ++i) {if (i % 64 && i % 4 == 0) putchar(' ');else if (i && i % 64 == 0) putchar('\n');putchar(a[i]);}printf("\n%d\n", cur);return true;}for (int i = 0; i < L; ++i) {bool ok = true;a[cur] = 'A' + i;if (check(cur, i)) {cnt++;if (dfs(cur + 1)) return true;}}return false;}int main() {while (~scanf("%d%d", &n, &L) && (n || L)) {cnt = 0;dfs(0);}return 0;}
阅读全文
0 0
- 例题7-5 UVA 129 Krypton Factor (困难的串,搜索)
- 例题7-5 困难的串(Krypton Factor, UVa 129)
- 困难的串(Krypton Factor,UVa 129)
- Uva 129 Krypton Factor(困难的串)
- 困难的串(Krypton Factor,UVa 129)
- UVA-129 Krypton Factor 困难的串
- 困难的串(Krypton Factor,UVa 129)
- UVa #129 Krypton Factor (例题7-5)
- UVA 129 困难的串Krypton Factor (回溯法)
- 困难的串(Krypton Factor,UVa129)
- uva 129 Krypton Factor
- uva 129 - Krypton Factor
- UVa 129 Krypton Factor
- UVA - 129 Krypton Factor
- UVa-129 - Krypton Factor
- UVa - 129 - Krypton Factor
- UVA - 129 Krypton Factor
- uva 129 - Krypton Factor
- python Web爬取工具总结 1 :Requests和BeautifulSoup
- [bzoj1968][数论]约数研究
- Jdk8 Optional 的正确姿势
- IntentService使用及源码解析
- ssh 免密码登录
- 例题7-5 困难的串(Krypton Factor, UVa 129)
- Topcoder SRM 721 Div.2 C. ApocalypseEasy
- Android-Java 小知识点整理
- Maven 常见问题解决
- java基础知识总结1
- 推荐一些非常有用的博客
- 自己做身份证社保等回执
- Codeforces Round #435 (Div. 2)-异或规律&思维-Mahmoud and Ehab and the xor
- C++输入正整数,输出1-n*n顺时针排列矩阵之动态分配