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)的更多相关文章

  1. HDU 1627 Krypton Factor

    回溯法:避免无用判断,强化回溯代码的实现过程 题目的大意就是以字典序为准,排列字符串,但要保证一个字符串中不包含相邻的重复子串. Problem Description For example, th ...

  2. UVa 129 Krypton Factor (DFS && 回溯)

    题意 : 如果一个字符串包含两个相邻的重复子串,则称它是“容易的串”,其他串称为“困难的 串”.例如,BB.ABCDACABCAB.ABCDABCD都是容易的串,而D.DC.ABDAB. CBABCB ...

  3. UVA129 Krypton Factor 困难的串 dfs回溯【DFS】

     Krypton Factor Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  4. Krypton Factor

    Krypton Factor Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  5. UVA.129 Krypton Factor (搜索+暴力)

    UVA.129 Krypton Factor (搜索+暴力) 题意分析 搜索的策略是:优先找长串,若长串不合法,则回溯,继续找到合法串,直到找到所求合法串的编号,输出即可. 注意的地方就是合法串的判断 ...

  6. 129 - Krypton Factor

    /*UVa129 - Krypton Factor --回溯问题.看例子可知道确定该字符串是按照从左到右依次考虑每个位置,当前位置填不上所有的字符时,需要回溯. -- */ #define _CRT_ ...

  7. HDOJ(HDU).2660 Accepted Necklace (DFS)

    HDOJ(HDU).2660 Accepted Necklace (DFS) 点我挑战题目 题意分析 给出一些石头,这些石头都有自身的价值和重量.现在要求从这些石头中选K个石头,求出重量不超过W的这些 ...

  8. HDOJ(HDU).1045 Fire Net (DFS)

    HDOJ(HDU).1045 Fire Net [从零开始DFS(7)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HD ...

  9. HDOJ(HDU).1241 Oil Deposits(DFS)

    HDOJ(HDU).1241 Oil Deposits(DFS) [从零开始DFS(5)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...

随机推荐

  1. Sping Boot返回Json格式自定义

    转载请注明http://www.cnblogs.com/majianming/p/8491020.html 在写项目过程中,遇到了需要定义返回的json字段格式的问题 例如在实体属性中,我有一个字段是 ...

  2. [转]Windows Azure安全概述

    本文转自:http://blogs.msdn.com/b/azchina/archive/2011/03/06/windows_5f00_azure_5f00_security_5f00_overvi ...

  3. Hadoop YARN学习之重要术语总结(6)

    Hadoop YARN学习之重要术语总结(6) - SLA服务等级 - RM(ResourceManager) - AM(ApplicationMaster) - NM(NodeMaster) - M ...

  4. 白话容器namespace

    进入正题之前是例行装X环节: 过年7天吃的,花了45天又回来了. 近年来容器大火,也正是因为容器,生生灭掉了一个IT岗位!哥也是被生生的逼上了邪路. 那究竟什么是容器呢? 就三个字:它就是个进程!(多 ...

  5. Android 实现对多个EditText的监听

    create_account=(EditText)findViewById(R.id.create_account); create_password=(EditText)findViewById(R ...

  6. git ---合并和删除分支

    git merge  分支名 //合并子分支到当前分支 git branch -d 分支名//删除分支

  7. 12. binary search Trees

    12. binary search Trees    The search tree data structure supports many dynamic-set operations,inclu ...

  8. windows上把git生成的ssh key

    右键鼠标,选中 “Git Bash here”: 输入指令,创建ssh key: cd ~/.ssh/ #bash: cd: /c/Users/Administrator/.ssh/: No such ...

  9. zookeeper启动

    Zookeeper启动总结1.实际项目用的是Linux,问题不大,本地开发学习用Windows,问题多多.2.Zookeeper3.5.1-alpha,和本地JDK1.7,有冲突,无法正常启动.3.Z ...

  10. Win10浏览器Spartan无法全屏

    昨天尝鲜win10 Build 10074 msdn pro版,新版微软吹嘘的Spartan浏览器看视频是无法像IE一样全屏的.网上搜索了一下也没有解决方法.不过看到一个可以打开隐藏设置实验功能的方法 ...