Joke with permutation search

Source: Internet
Author: User

                      Joke with permutation

Abstract: For the arrangement of 1~n, the integers are separated by spaces. Now remove the space and become a numeric string with no spaces. Please restore him, if there are multiple, output any one can.

Analysis: First according to the length can go out n. and then search.  Give the DFS string positional parameters. For each position character cur, you can make up an integer or an integer with the next one.

does not form an integer x, it will flag[x] = 1. Note that 0 can only be in two-digit integers for everyone.

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cstring>5#include <algorithm>6#include <string>7#include <vector>8#include <Set>9#include <map>Ten#include <queue> One#include <stack> A using namespacestd; -typedefLong LongLL; - ConstLL INF =0x4fffffff; the Const Doubleexp= 1e-5; - ConstLL MOD = 1e9+7; - Const intms= the; -  + BOOLFlag[ms]; - BOOLTag[ms]; + CharStr[ms]; A BOOLOver ; at intLen,n; -  - voidDfsintcur) - { -     if(over) -         return ; in     if(cur >=len) -     { to          for(inti =0; i < Len; i++) +         { -printf"%c", Str[i]); the                 if(Tag[i] = =1&& i! = Len-1 ) *printf" "); $         }Panax Notoginsengover =true; -         return ; the     } +  A     //0 digits in a double-digit integer only. This ensures that the cur location in the next DFS will not be 0. the  +     if(!flag[str[cur]-'0'] && (cur +1>= Len | | Str[cur +1] !='0')) -     { $Tag[cur] =1;//This means that an integer is formed at this position, making it easy to determine the position of the space.  $Flag[str[cur]-'0'] =1; -DFS (cur +1); -Tag[cur] =0;//Fallback .  theFlag[str[cur]-'0']  =0; -     }Wuyi  the     if(!flag[(Str[cur)-'0') *Ten+ Str[cur +1] -'0'] && ((str[cur)-'0') *Ten+ str[cur+1] -'0') <= n && (cur +2>= Len | | Str[cur +2] !='0')) -     { WuTag[cur +1] =1; -flag[(Str[cur]-'0') *Ten+ Str[cur +1] -'0'] =1; AboutDFS (cur +2); $Tag[cur +1] =0; -flag[(Str[cur]-'0') *Ten+ Str[cur +1] -'0'] =0; -     } - } A  +  the intMain () - { $scanf"%s", str); theLen =strlen (str); the     if(Len <=9) the     { the          for(inti =0; i < Len; i++) -         { in                 if(i = =0) theprintf"%c", Str[i]); the                 Else Aboutprintf"%c", Str[i]); the         } the         return 0; the     } +n = (len-9) /2+9; -over =false; thememset (Flag,0,sizeof(flag));Bayimemset (Tag,0,sizeof(tag)); theDfs0); the     return 0; -}

Joke with permutation search

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.