48- prove safety offer- face questions no repeating longest substring of characters - Dynamic Programming

/ * 
Title: 
	longest substring contain repeated characters. 
* / 
/ * 
Idea: 
	F (I) = F (I-. 1) +. 1, (does not appear over the current character, Distance> F (I-. 1) 
		   Distance, from the character of a current appears and the characters 
* / 
# the include <the iostream> 
#include <CString> 
#include <Vector> 
#include <algorithm> 


the using namespace STD; 


int longestSubstringWithoutDuplication (String STR) { 
    int EN [26 is]; 
    Memset (EN, -1, the sizeof (EN)); 
    int str.size = len (); 
    int maxVal = 0; 
    int Curr = 0; 
    for (int I = 0; I <len; I ++) { 
        IF (EN [STR [I] - 'A'] == -1) { 
            Curr + = Curr. 1; 
        } the else { 
            int I = D - EN [STR [I] - 'A']; 
            IF (D> Curr) {
                curr++;
            }else{
                if(curr > maxVal){
                    maxVal = curr;
                }
                curr = d;
            }
        }
        cout<<str[i]<<" "<<i<<" "<<curr<<endl;
        en[str[i]-'a'] = i;
    }
    return max(curr,maxVal);
}

int main(){
    string str="arabcacfr";
    cout<<longestSubstringWithoutDuplication(str);

    return 0;
}

    

Guess you like

Origin www.cnblogs.com/buaaZhhx/p/12051392.html