ACM Topic ———— Difficult string

Source: Internet
Author: User

Title Description

If a string contains two contiguous repeating substrings, it is called an "easy string", and the other strings are called "difficult strings". For example, BB,ABCDACABCAB,ABCDABCD are easy strings, and D,dc,abdab,cbabcbad are difficult strings.

Input

Enter positive integers n and L.

Output

The output consists of a string of the first L strings, a dictionary order K small difficult string. For example, when L=3, the first 7 difficult strings were a,ab,aba,abac,abaca,abacab,abacaba. Enter a guaranteed answer of no more than 80 characters.

Sample input
7 330 3
Sample output
Abacabaabacabcacbabcabacabcacbacaba

Success on the small white knocked once, but the egg, do not know the problem.

Difficult string # include <iostream> #include <string.h> #include <stdio.h>using namespace Std;int N, s[1001], L, Cnt;int DFS (int cur) {    if (cnt + = = N)    {        for (int i=0; i<cur; i++) printf ("%c", ' A ' +s[i]);        printf ("\ n");        return 0;    }    for (int i=0; i<l; i++)    {        S[cur] = i;        int OK = 1;        for (int j=1; j*2<=cur+1; j + +)        {            int e = 1;            for (int k=0; k<j; k++)                if (s[cur-k]! = S[cur-k-j])                {                    e = 0;                    break;                }            if (e)            {                OK = 0;                break;            }        }        if (OK) if (! DFS (cur+1)) return 0;    }    return 1;} int main () {while    (~scanf ("%d%d", &n, &l))    {        cnt = 0;        Memset (s,0,sizeof (s));        DFS (0);    }    return 0;}

ACM Topic ———— Difficult string

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.