hdu - 1627 Krypton Factor (dfs)
http://acm.hdu.edu.cn/showproblem.php?pid=1627
给定 n 和 L 找出第n个范围在0-L之内的字符串,字符串要求没有相邻的子串是相同的。
按照格式输出。
这个题的关键在于判断字符串是否是符合要求的字符串.
枚举字符串所有子串可能的长度,然后判断即可。
- #include <iostream>
- #include <cstdio>
- #include <cmath>
- #include <vector>
- #include <cstring>
- #include <string>
- #include <algorithm>
- #include <string>
- #include <set>
- #include <functional>
- #include <numeric>
- #include <sstream>
- #include <stack>
- #include <map>
- #include <queue>
- #pragma comment(linker, "/STACK:102400000,102400000")
- #define CL(arr, val) memset(arr, val, sizeof(arr))
- #define ll long long
- #define inf 0x7f7f7f7f
- #define lc l,m,rt<<1
- #define rc m + 1,r,rt<<1|1
- #define pi acos(-1.0)
- #define L(x) (x) << 1
- #define R(x) (x) << 1 | 1
- #define MID(l, r) (l + r) >> 1
- #define Min(x, y) (x) < (y) ? (x) : (y)
- #define Max(x, y) (x) < (y) ? (y) : (x)
- #define E(x) (1 << (x))
- #define iabs(x) (x) < 0 ? -(x) : (x)
- #define OUT(x) printf("%I64d\n", x)
- #define lowbit(x) (x)&(-x)
- #define Read() freopen("a.txt", "r", stdin)
- #define Write() freopen("b.txt", "w", stdout);
- #define maxn 1000000000
- #define N 2510
- #define mod 1000000000
- using namespace std;
- int n,m;
- int a[];
- void dfs(int cur)
- {
- for(int i=;i<m;i++)
- {
- a[cur]=i;
- bool is=;
- for(int j=;*j<=cur+;j++) //枚举 所有 的可能长度,
- {
- bool flag=;
- for(int k=;k<j;k++) //判断是否符合要求
- if(a[cur-k]!=a[cur-j-k]) {flag=;break;}
- if(!flag)
- {
- is=;
- break;
- }
- }
- if(is) continue;
- if(--n==)
- {
- for(int j=;j<=cur;j++)
- {
- if(j&&j%==) printf("\n");
- else if(j&&j%==) printf(" ");
- printf("%c",a[j]+'A');
- }
- printf("\n");
- printf("%d\n",cur+);
- }
- dfs(cur+);
- if(n==) return;
- }
- }
- int main()
- {
- //freopen("a.txt","r",stdin);
- while(~scanf("%d%d",&n,&m))
- {
- if(n==&&m==) break;
- dfs();
- }
- return ;
- }
hdu - 1627 Krypton Factor (dfs)的更多相关文章
- HDU 1627 Krypton Factor
回溯法:避免无用判断,强化回溯代码的实现过程 题目的大意就是以字典序为准,排列字符串,但要保证一个字符串中不包含相邻的重复子串. Problem Description For example, th ...
- UVa 129 Krypton Factor (DFS && 回溯)
题意 : 如果一个字符串包含两个相邻的重复子串,则称它是“容易的串”,其他串称为“困难的 串”.例如,BB.ABCDACABCAB.ABCDABCD都是容易的串,而D.DC.ABDAB. CBABCB ...
- UVA129 Krypton Factor 困难的串 dfs回溯【DFS】
Krypton Factor Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- Krypton Factor
Krypton Factor Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- UVA.129 Krypton Factor (搜索+暴力)
UVA.129 Krypton Factor (搜索+暴力) 题意分析 搜索的策略是:优先找长串,若长串不合法,则回溯,继续找到合法串,直到找到所求合法串的编号,输出即可. 注意的地方就是合法串的判断 ...
- 129 - Krypton Factor
/*UVa129 - Krypton Factor --回溯问题.看例子可知道确定该字符串是按照从左到右依次考虑每个位置,当前位置填不上所有的字符时,需要回溯. -- */ #define _CRT_ ...
- HDOJ(HDU).2660 Accepted Necklace (DFS)
HDOJ(HDU).2660 Accepted Necklace (DFS) 点我挑战题目 题意分析 给出一些石头,这些石头都有自身的价值和重量.现在要求从这些石头中选K个石头,求出重量不超过W的这些 ...
- HDOJ(HDU).1045 Fire Net (DFS)
HDOJ(HDU).1045 Fire Net [从零开始DFS(7)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HD ...
- HDOJ(HDU).1241 Oil Deposits(DFS)
HDOJ(HDU).1241 Oil Deposits(DFS) [从零开始DFS(5)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...
随机推荐
- .net主站和二级域名下实现session共享
public class CrossDomainCookie : IHttpModule { private string m_RootDomain = string.Empty; #region I ...
- hihocoder编程练习赛52-1 字符串排序
思路: 将字符串按照新的顺序映射之后再排序. 实现: #include <bits/stdc++.h> using namespace std; int main() { int n; s ...
- BaseAdapter的优化
传统的 package cct.commonadapter.bean; import android.content.Context; import android.view.LayoutInflat ...
- SQL SERVER的数据类型
1.SQL SERVER的数据类型 数据类弄是数据的一种属性,表示数据所表示信息的类型.任何一种计算机语言都定义了自己的数据类型.当然,不同的程序语言都具有不同的特点,所定义的数据类型的各类和名称都或 ...
- 最全的Java面试宝典
一. 前言部分 从享受生活的角度上来说:“程序员并不是一种最好的职业,我认为两种人可以做程序员,第一,你不做程序员,你就没有什么工作可做,或者说是即使有可以做的工作但是你非常不愿意去做:第二,你非常痴 ...
- JS对json中某字段进行排序
var data =[ { "cid":1, "name":"aaa", "price":1000 },{ " ...
- css 样式渲染
1.文字过长时,自动换行
- col - 过滤掉输入中的反向换行符
SYNOPSIS(总览) col [-bfx ] [ Fl l Ar num ] DESCRIPTION(描述) Col 过滤掉反向(以及半反向)换行符(LF: line feed or NL: ne ...
- cesium 原理 之 command拼接
VAO VAO(Vertext Array Object),中文是顶点数组对象.之前在<Buffer>一文中,我们介绍了Cesium如何创建VBO的过程,而VAO可以简单的认为是基于VBO ...
- CAD参数绘制块引用对象(网页版)
主要用到函数说明: _DMxDrawX::DrawBlockReference 绘制块引用对象.详细说明如下: 参数 说明 DOUBLE dPosX 插入点的X坐标 DOUBLE dPosY 插入点的 ...