light topics explain 7.25 simulation game T1

Experience: This questions is actually playing their own violence to break out

I did not expect positive solution really is an enumeration of violence

 

My approach is this

A string is of length enumeration substring of x

See if it is a string of sequences B

Next is my despair exam number (100 AC)

// Light 
/ * 
My personal idea of the questions that is half the answer to violence + 

* / 
#include <bits / STDC H ++.>
 A using  namespace std;
 String A, B;
 / * 
can reverse a string enumeration, with ne [i ] [j] represents a j + 'a' position of the letter position i 
* / 
int NE [ 2000 ] [ 26 is ]; / * 
void Yuchuli () { 
    for (int i = B.length () -. 1; i> = 0; I -) { 
        int J = B [I] - 'A'; 
        int K = I-. 1; 
        ! the while (K> = 0 && B [K] - 'A' = J) { 
            NE [K] [ J] = I; 
            K--; 
        // COUT << << K '' << << J '' << B [I] << endl;
        }
        if(B[k]-'a'==j) 
            ne [k] [j] = i;
    }
}*/
int Zixulie(int l,int r){
    int i=l;int k=0;
//    cout<<l<<" "<<r<<endl;
    while(k<B.length()){
    //    j=ne[j][A[i]-'a'];
        int flag=0;
        for(int j=k;j<B.length();j++)
            if(A[i]==B[j]){
                flag=1;
            //    cout<<i<<" "<<A[i]<<" "<<j<<" "<<B[j]<<" "<<k<<endl;
                k=j+1; I ++;
                 // COUT I << << "" << endl << J; 
                BREAK ; 
            } 
        IF (In Flag == 0 )
             BREAK ; 
    } 
    IF (I> R & lt)
         return  . 1 ;
     the else 
        return  0 ; 
} 
BOOL Check ( int LLENA ) {
     // now that it has been pre-out interval is determined whether an enumeration sequence 
    for ( int I = 0 ; I + llenA- . 1 <A.length (); I ++ )
         iF (Zixulie (I, I + LLENA - 1 ) == 0)
            return false;
    return true;
}
int main()
{
    //freopen("light.in","r",stdin);
    //freopen("light.out","w",stdout);
    cin>>A>>B;
//    Yuchuli();
//    for(int i=0;i<B.length();i++){
//        for(int j=0;j<26;j++)
//            cout<<ne[i][j]<<" ";
//        cout<<endl;
//    }


    int l=0,r=2001,ans=-1;
    while(l<r){
        int mid=(l+r)>>1;
        if(mid>A.length()||mid>B.length()){
            r=mid-1;
            continue;
        }
    //    cout<<l<<" "<<r<<endl;
        if(check(mid)==0){
            ans=mid;
            r=mid;
        }
        else
            l=mid+1;
    }
    cout<<ans;
    return 0;
}/*
aabbcc
ABCABC



Thursday Tido 2019/7/25 10:41:04 
abcdefddbba 
aabbcce 

* /

Can be seen, I would like to put a question complicated

Or that I think this question is very troublesome that their code is cumbersome

I have a lot of places in the program is actually not necessary

For example, half of the answer

In fact, one small to large enumeration on the line (in fact, will do)

 

Then I judge a place to start and a little trouble

 

Positive solution to this questions is the teacher

 

I as a starting point is to enumerate, j substrings of length at most n- 2

( "" I started also considering optimization)

n maximum 2000 2000 2 = 4000000 = 4 × 10 6 but it is still acceptable hungry Oh

To sum up the questions that violence solves a super simple analog enumeration friends

 

After doing a little problem when their own thoughts and ideas a little confidence

You still have to learn to count time complexity and space, to avoid the card bug!

Biu pressurized oil

Guess you like

Origin www.cnblogs.com/Tidoblogs/p/11244660.html