例题7-5 UVA 129 Krypton Factor (困难的串,搜索)
来源:互联网 发布:精易论坛淘宝采集 编辑:程序博客网 时间:2024/05/02 00:09
题意:
给你n 和l ,求出按字典序来算第n小的由前l 个字母组成的困难的串,如果一个字符串中包含两个相邻的重复子串,那么是容易的串,否则是困难的串。
思路:
直接搜索即可!
当枚举到第c 位时,我们只需要判断后缀是否重复即可,因为前面的都已经判断过了。另外如果一个字母一个字母枚举的话,那么就已经保证了字典序的顺序了,无需在排序了。
输出格式注意下即可。
#include <cstdio>#include <cstring>#include <vector>#include <algorithm>#include <string>using namespace std;int n,l;char s[100];int al = 0;int flag = 0;void print(){ int len = strlen(s); for (int i = 0; i < len; ++i){ if (i % 64 == 0 && i) printf("\n%c",s[i]); else if (i % 4 == 0 && i) printf(" %c",s[i]); else putchar(s[i]); } putchar('\n'); printf("%d\n",len);}void dfs(int c){// printf("c = %d\n",c); if (flag) return; for (int i = 0; i < l; ++i){ s[c] = i + 'A'; bool ok = 1; for (int j = 2; c-j+1 >= 0; j += 2){ string t1 = ""; string t2 = ""; for (int k = c-j+1; k <= c-j/2; ++k){ t1+= s[k]; } for (int k = c-j/2+1; k <= c; ++k){ t2 += s[k]; } if (t1 == t2){ ok = 0; break; } } if (ok){ s[c+1] = 0; if (++al == n) { print(); flag = 1; return; } dfs(c+1); } }}int main(){// freopen("out.txt","w",stdout); while(~scanf("%d %d",&n, &l) && (n || l)){ al = flag = 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
- 微信自动回复功能
- 线上应用故障排查之一:高CPU占用
- html5(五)媒体
- Codeforces Round #392(Div. 2) A Holiday Of Equality【水题】
- 2016 年度消费信贷建模小结
- 例题7-5 UVA 129 Krypton Factor (困难的串,搜索)
- Echarts 经验
- 如何修改Android APP的图标和名字
- Sqoop2-2:There are issues with entered data, please revise your input:
- php 读取TXT文本生成 想要的数据格式
- 【VS开发】【miscellaneous】 Windows下配置Git
- HandlerThread深入理解
- Android Studio设置注释模板
- xml可以分页案例