Rnqoj (non-appearing substring)

Source: Internet
Author: User

Topic Link: Portal

The main topic: slightly;

Topic Idea: DP thought

After the data is read, it is traversed backwards, if we are looking for all sequences of a number string with a length of N of 1, then it can be represented as 1+ (a sequence with a length of n-1 at the beginning of any number)

Then we want to see which substrings in the sequence did not appear, that is (the sequence of any number beginning with the length of n-1) does not appear in the substring, with the DP array can be understood as dp[i]=x is, all 1~q of the DP array should be greater than or equal to X-1

#include <iostream>#include<cstdio>#include<cstdlib>#include<cmath>#include<algorithm>#include<cstring>#include<stack>#include<cctype>#include<queue>#include<string>#include<vector>#include<functional>#include<Set>#include<map>#include<climits>#defineLson Root<<1,l,mid#defineRson Root<<1|1,mid+1,r#defineFi first#defineSe Second#definePing (x, y) ((x-y) * (x-y))#defineMST (x, y) memset (x,y,sizeof (x))#defineMCP (x, y) memcpy (x,y,sizeof (y))using namespacestd;#defineGamma 0.5772156649015328606065120#defineMOD 1000000007#defineINF 0x3f3f3f3f#defineN 100005#defineMAXN 100005typedef pair<int,int>Pii;typedefLong LongLL;intn,vis[ -],k;intdp[ One];inta[100005];intMain () {intI,j,group; scanf ("%d%d",&n,&k);  for(i=1; i<=n;++i) {scanf ("%d",&a[i]);}  for(i=n;i>=1;--i) {        intm=inf;  for(j=1; j<=k;++j) M=min (m,dp[j]); Dp[a[i]]=m+1; }    intm=inf;  for(i=1; i<=k;++i) m=min (m,dp[i]); printf ("%d\n", m+1); return 0;}

Rnqoj (non-appearing substring)

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.