uva 129 Kryptopn Factor 暴力回溯
来源:互联网 发布:剖腹产算日子软件下载 编辑:程序博客网 时间:2024/06/06 12:48
点击打开链接
cur之前无相同相邻子串,path[cur]加入后,只需判断后缀cur是否存在相邻重复子串即可
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>using namespace std;const int N=1e4+20;char path[N];int cnt;int n,l;bool check(int cur){for(int l=1;l<=(cur+1)/2;l++)// len of the repeted sub{int equal=1;//cur之前无相同相邻子串 for(int i=0;i<l;i++)//判断后缀cur是否存在相邻重复子串即可 {if(path[cur-i]!=path[cur-l-i]){equal=0;break;}}if(equal)return false;}return true;}int dfs(int cur){if(cnt==n){for(int i=0;i<cur;i++){if(i&&i%4==0){if(i%64==0)printf("\n");elseprintf(" ");}printf("%c",path[i]);}printf("\n%d\n",cur);return 1;}for(int i=0;i<l;i++){path[cur]='A'+i;if(check(cur))//add s[i] to path{cnt++;if(dfs(cur+1))return 1;}}return 0;}int main(){while(cin>>n>>l&&(n+l))//n'th {cnt=0;dfs(0);}return 0;}
0 0
- uva 129 Kryptopn Factor 暴力回溯
- UVa 129 Krypton Factor (回溯好题)
- UVA - 129 Krypton Factor (回溯)
- UVA - 129 Krypton Factor 回溯+剪枝
- UVa 129 - Krypton Factor (DFS 回溯)
- UVa 129:Krypton Factor(回溯)
- UVa-129-Krypton Factor(回溯法)
- UVA.129 Krypton Factor (搜索+暴力)
- UVa 129 - Krypton Factor(DFS+回溯)
- 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
- uva 129 - Krypton Factor
- 浏览器缓存
- StringTokenizer or Split
- Spring依赖注入---<2>
- qt如何通过ODBC连接mysql数据库
- sqlldr的用法 (这个最完整)
- uva 129 Kryptopn Factor 暴力回溯
- python练题--游戏式闯关挑战
- 51nod1678
- 构建单页Web应用
- Linux重启网络
- 前端速学成财:第八课-速玩JS文件合并和压缩
- OpenWrt挂载U盘安装软件注意事项
- 安装ElasticSearch
- 安卓的内存泄漏问题总结