uva129||hdu 1627 Krypton Factor 回溯法
来源:互联网 发布:tensorflow finetune 编辑:程序博客网 时间:2024/05/16 16:01
题意:用前l个大写的字母构成没有相邻子串的字符串,这种串称作困难串,求出前n个困难串,并按格式输出
#include<cstdio>using namespace std;int n,l,cnt;char a[100];bool dfs(int cur){if(cnt++==n){for(int i=0;i<cur;i++){if(i%64==0&&i)printf("\n");else if(i%4==0&&i)printf(" ");printf("%c",a[i]+'A');}printf("\n");printf("%d\n",cur);return true;}for(int i=0;i<l;i++){a[cur]=i;//试探iint ok=1;for(int j=1;j*2<=cur+1;j++){int equal=1;for(int k=0;k<j;k++)//检查长度为j的子串是否相等 a[cur-2*j+1~ cur-j]a[cur-j+1 ~ cur] {if(a[cur-k]!=a[cur-j-k])//cur-2*j+1>=0 2*j<=cur+1{equal=0;break;}}if(equal){ok=0;break;//有相同相邻子串,不符,不能继续递归,继续试探}}if(ok){if(dfs(cur+1))return true;}}return false;}int main(){while(scanf("%d%d",&n,&l)&&(n+l)){cnt=0;dfs(0);}}
0 0
- uva129||hdu 1627 Krypton Factor 回溯法
- [回溯]Krypton Factor UVA129
- UVa129 - Krypton Factor
- UVA129 - Krypton Factor
- UVA129-Krypton Factor
- UVA129 Krypton Factor
- BNU17268 UVA129 Krypton Factor
- uva129 Krypton Factor
- Uva129 Krypton Factor【dfs回溯】【例题7-5】
- HDU-1627-Krypton Factor
- hdu1627 Krypton Factor(回溯法)
- UVa-129-Krypton Factor(回溯法)
- UVA129 —— Krypton Factor (氪因素)
- 困难的串(Krypton Factor,UVa129)
- UVA 129 困难的串Krypton Factor (回溯法)
- UVa129 - Krypton Factor 不错的DFS入门题
- UVa 129 Krypton Factor (回溯好题)
- UVA - 129 Krypton Factor (回溯)
- GDB调试
- 观察者模式
- Tornado自定义分布式session框架
- compareTo方法和compare方法
- 认识Xcode的调试器:LLDB调试技术
- uva129||hdu 1627 Krypton Factor 回溯法
- Linux_Service—NFS
- random.nextInt()与Math.random()基础用法
- bzoj1078: [SCOI2008]斜堆
- MyBatis(二)
- 数据库oracle,pgsq,mysql.相关设置
- HTML 语言代码参考手册
- 【图像处理】图像的极坐标变换
- c++中指针与引用的区别