hdu1627 Krypton Factor

Source: Internet
Author: User

Title Description:

Any combination of the first L characters in the given a-Z;

Hard string for the combined resulting string that does not contain adjacent repeating strings

Solving nth hard strings by dictionary order


The thinking of solving problems: Backtracking method can


#include <cstring> #include <cstdio>using namespace std;int n,l;char ans[82];bool check (int len) {int flag=f    Alse;        for (int t=len-1; t>= (len+1)/2; t--) {int i=t;        int J=len;            while (j>t) {if (ans[i]!=ans[j]), break;        I--, j--;            } if (j==t) {flag=true;        Break }} return flag;}    int t;bool dfs (int len) {if (t==n) return true;    if (len==80) return false;        for (int i=0; i<l; i++) {ans[len+1]= ' A ' +i;            if (!check (len+1)) {t++;        if (Dfs (len+1)) return true;    } ans[len+1]= ' + '; } return false;} int main () {while (scanf ("%d%d", &n,&l) ==2&& (n!=0| |        l!=0)) {memset (ans,0,sizeof (ans));        t=0;        DFS (0);        int Len=strlen (ans+1);            for (int i=1; i<=len; i++) {printf ("%c", Ans[i]); if (i%64==0&&i<len) {printf ("\ n");            Continue        } if (I%4==0&&i<len) printf ("");        } printf ("\ n");    printf ("%d\n", Len); } return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

hdu1627 Krypton Factor

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.