第七章 回溯算法part02

49 阅读9分钟

第七章 回溯算法part02

39. 组合总和 40.组合总和II 131.分割回文串

39. 组合总和

题目地址 :

39. 组合总和 - 力扣(LeetCode)

Code ( 用时 仍然 较多 ) :

class Solution {
public:
​
    struct Fuction_unordered_set_Hash_VectorInt
    {
        size_t operator()(const vector<int> & vec_In) const{
​
            std::size_t seed = 0 ;
            std::hash<int> hasher ;
​
​
            vector<int> vec_Process(vec_In) ;
​
            sort(vec_Process.begin(),vec_Process.end()) ;
​
            for(auto &address_i : vec_Process )
            //for(auto &address_i : vec_In )
            {
                seed ^= hasher(address_i) + 0x9e3779b9 + ( seed << 6 ) + ( seed >> 2 ) ;
​
​
            }
​
            return seed ;
​
​
​
        }
​
        
​
​
    };
​
    // struct Fuction_unordered_set_Equal_VectorInt
    // {
    //     bool operator()(const vector<int> & vec_1_In , const vector<int> & vec_2_In )const{
​
    //         for(int i = 0 ; i < vec_1_In.size() ; i++ )
    //         {
    //             if(vec_1_In[i] == vec_2_In[i])
    //             {
​
    //                 continue ;
​
​
    //             }
    //             else
    //             {
​
    //                 return false ;
​
    //             }
​
​
    //         }
​
    //         return true ;
​
​
​
​
    //     }
​
​
    // };
​
    struct Fuction_unordered_set_Equal_VectorInt
    {
        bool operator()(const vector<int> & vec_1_In , const vector<int> & vec_2_In )const{
​
            vector<int> vec_1_Process (vec_1_In);
            vector<int> vec_2_Process (vec_2_In);
​
            sort(vec_1_Process.begin() , vec_1_Process.end()) ;
            sort(vec_2_Process.begin() , vec_2_Process.end()) ;
​
            for(int i = 0 ; i < vec_1_Process.size() ; i++ )
            {
                if(vec_1_Process[i] == vec_2_Process[i])
                {
​
                    continue ;
​
​
                }
                else
                {
​
                    return false ;
​
                }
​
​
            }
​
            return true ;
​
​
​
​
        }
​
​
    };
​
​
​
    vector<vector<int>> combinationSum(vector<int>& candidates, int target) {
​
        int length_candidates = candidates.size() ;
​
​
​
        vector<int> vec_Cache_NumSequence ;             // 题目 要求 是 无序 级 
                                                        // 这里 是 有序  
​
        vector<vector<int>> vec_2_Dimention_For_Receive_And_Return ;
​
        unordered_set<vector<int> , Fuction_unordered_set_Hash_VectorInt , Fuction_unordered_set_Equal_VectorInt > unordered_set_VecInt_Result_Maintain ;
​
​
​
        int num_Temp_Cache_For_Sum = 0 ;
​
​
        int num_Whole_Layers ;
​
        sort(candidates.begin(),candidates.end());
​
        if(target != 0 )
        {
            //num_Whole_Layers = target / 2 ;
            num_Whole_Layers = target / candidates[0] ;
​
            //num_Whole_Layers = 10 ;
​
        }
        else
        {
            num_Whole_Layers = target ;
​
​
        }
​
        
​
​
        for(int i = 1 ; i <= num_Whole_Layers ; i++ )
        {
​
            //cout<<"i = "<<i <<endl;
​
            fuction_Recursion_For_forLoop(i , 0 , length_candidates , 1 , vec_Cache_NumSequence , vec_2_Dimention_For_Receive_And_Return , candidates , num_Temp_Cache_For_Sum , target , unordered_set_VecInt_Result_Maintain )   ;
​
​
        }
​
​
​
        return vec_2_Dimention_For_Receive_And_Return ;
​
​
​
​
        
    }
​
    // 减枝
​
    void fuction_Recursion_For_forLoop(int num_Whole_Layers , int i_Work_In , int length_candidates , int i_Layer , vector<int> & vec_Cache_NumSequence , vector<vector<int>> & vec_2_Dimention_For_Receive_And_Return , vector<int>& candidates , int & num_Temp_Cache_For_Sum , int target  , unordered_set<vector<int> , Fuction_unordered_set_Hash_VectorInt , Fuction_unordered_set_Equal_VectorInt > & unordered_set_VecInt_Result_Maintain   )
    {
​
        // 不要 忘了  输出 (“ 标准 打印  ”)  占用 的 时间  
​
        //cout<<"num_Whole_Layers = " <<num_Whole_Layers<<endl;
        if(i_Layer != num_Whole_Layers )
        {
​
            for(int i = i_Work_In ; i < length_candidates ; i++ )
            {
​
                int num_Temp_Cache_For_candidateElement = candidates[i] ;
​
                num_Temp_Cache_For_Sum += num_Temp_Cache_For_candidateElement ;
​
                vec_Cache_NumSequence.push_back(num_Temp_Cache_For_candidateElement) ;
​
                // 减枝
​
                if(num_Temp_Cache_For_Sum > target )
                {
                    // return ;
​
                    num_Temp_Cache_For_Sum -= num_Temp_Cache_For_candidateElement ;
​
                    vec_Cache_NumSequence.pop_back() ;
​
                    // Cache 信息 的 维护  
​
                    continue ;
​
                }
​
                //
                //fuction_Recursion_For_forLoop(num_Whole_Layers , ( i_Work_In + 1 ) , length_candidates , (i_Layer + 1 ) , vec_Cache_NumSequence ,vec_2_Dimention_For_Receive_And_Return , candidates , num_Temp_Cache_For_Sum , target  ) ;
                fuction_Recursion_For_forLoop(num_Whole_Layers , ( 0 ) , length_candidates , (i_Layer + 1 ) , vec_Cache_NumSequence ,vec_2_Dimention_For_Receive_And_Return , candidates , num_Temp_Cache_For_Sum , target , unordered_set_VecInt_Result_Maintain  ) ;
​
​
                num_Temp_Cache_For_Sum -= num_Temp_Cache_For_candidateElement ;
​
                vec_Cache_NumSequence.pop_back() ;
​
​
​
​
​
            }
​
​
​
​
        }
        else
        {
​
            for(int i = i_Work_In ; i <  length_candidates  ; i++ )
            {
​
                int num_Temp_Cache_For_candidateElement = candidates[i] ;
​
                num_Temp_Cache_For_Sum += num_Temp_Cache_For_candidateElement ;
​
                vec_Cache_NumSequence.push_back(num_Temp_Cache_For_candidateElement) ;
​
                //
​
                //cout<< "num_Temp_Cache_For_Sum = " << num_Temp_Cache_For_Sum << endl; 
​
                if(num_Temp_Cache_For_Sum == target )
                {
                    //sort(vec_Cache_NumSequence.begin() , vec_Cache_NumSequence.end()) ;
​
                    if(unordered_set_VecInt_Result_Maintain.find(vec_Cache_NumSequence) == unordered_set_VecInt_Result_Maintain.end()  )
                    {
                        vec_2_Dimention_For_Receive_And_Return.push_back(vec_Cache_NumSequence) ;
                        unordered_set_VecInt_Result_Maintain.insert(vec_Cache_NumSequence) ;
​
                    }
                    else
                    {
​
​
                    }
​
                    
​
                }
​
​
                num_Temp_Cache_For_Sum -= num_Temp_Cache_For_candidateElement ;
​
                vec_Cache_NumSequence.pop_back() ;
​
​
​
​
​
            }
​
​
​
​
​
        }
​
​
​
​
​
    }
​
​
};

40.组合总和II

题目链接 :

40. 组合总和 II - 力扣(LeetCode)

Code 1 ( Still 超时 (使用 了 散列表 对 集合 数组 进行 去重 ) ) :

class Solution {
public:
​
    struct Fuction_unordered_set_Hash_VectorInt
    {
        size_t operator()(const vector<int> & vec_In) const{
​
            std::size_t seed = 0 ;
            std::hash<int> hasher ;
​
​
            vector<int> vec_Process(vec_In) ;
​
            sort(vec_Process.begin(),vec_Process.end()) ;
​
            for(auto &address_i : vec_Process )
            //for(auto &address_i : vec_In )
            {
                seed ^= hasher(address_i) + 0x9e3779b9 + ( seed << 6 ) + ( seed >> 2 ) ;
​
​
            }
​
            return seed ;
​
​
​
        }
​
        
​
​
    };
​
​
​
    struct Fuction_unordered_set_Equal_VectorInt
    {
        bool operator()(const vector<int> & vec_1_In , const vector<int> & vec_2_In )const{
​
            vector<int> vec_1_Process (vec_1_In);
            vector<int> vec_2_Process (vec_2_In);
​
            sort(vec_1_Process.begin() , vec_1_Process.end()) ;
            sort(vec_2_Process.begin() , vec_2_Process.end()) ;
​
            for(int i = 0 ; i < vec_1_Process.size() ; i++ )
            {
                if(vec_1_Process[i] == vec_2_Process[i])
                {
​
                    continue ;
​
​
                }
                else
                {
​
                    return false ;
​
                }
​
​
            }
​
            return true ;
​
​
​
​
        }
​
​
    };
​
​
​
​
    vector<vector<int>> combinationSum2(vector<int>& candidates, int target) {
​
        int length_candidates = candidates.size() ;
​
        // vector<int> vec_Copy_candidates(candidates) ;
​
        // sort(vec_Copy_candidates.begin() , vec_Copy_candidates.end());
​
        // vector<int> vec_Int_Wait_For_Use ;
​
        vector<int> vec_Int_Wait_For_Use (candidates) ;
​
        sort(vec_Int_Wait_For_Use.begin() , vec_Int_Wait_For_Use.end() ) ;
​
        // for(int i = 0 ; i < vec_Copy_candidates.size() ; i++ )
        // {
        //     if((i + 1 ) < vec_Copy_candidates.size() && vec_Copy_candidates[i+1]!= vec_Copy_candidates[i])
        //     {
        //         vec_Int_Wait_For_Use.push_back(vec_Copy_candidates[i]);
​
​
        //     }
​
​
​
        // }
​
        int length_vec_Int_Wait_For_Use = vec_Int_Wait_For_Use.size() ;
​
​
​
        vector<int> vec_Cache_NumSequence ;             // 题目 要求 是 无序 级 
                                                        // 这里 是 有序  
​
        vector<vector<int>> vec_2_Dimention_For_Receive_And_Return ;
​
​
​
        int num_Temp_Cache_For_Sum = 0 ;
​
​
​
        unordered_set<vector<int> , Fuction_unordered_set_Hash_VectorInt , Fuction_unordered_set_Equal_VectorInt > unordered_set_VecInt_Result_Maintain ;
​
​
​
​
        for(int i = 1 ; i <= length_vec_Int_Wait_For_Use ; i++ )
        {
​
            //cout<<"i = "<<i <<endl;
​
            fuction_Recursion_For_forLoop(i , 0 , length_vec_Int_Wait_For_Use , 1 , vec_Cache_NumSequence , vec_2_Dimention_For_Receive_And_Return , vec_Int_Wait_For_Use , num_Temp_Cache_For_Sum , target , unordered_set_VecInt_Result_Maintain )  ;
​
​
        }
​
​
​
        return vec_2_Dimention_For_Receive_And_Return ;
​
​
​
​
        
    }
​
    void fuction_Recursion_For_forLoop(int num_Whole_Layers , int i_Work_In , int length_vec_Int_Wait_For_Use , int i_Layer , vector<int> & vec_Cache_NumSequence , vector<vector<int>> & vec_2_Dimention_For_Receive_And_Return , vector<int>& vec_Int_Wait_For_Use , int & num_Temp_Cache_For_Sum , int target , unordered_set<vector<int> , Fuction_unordered_set_Hash_VectorInt , Fuction_unordered_set_Equal_VectorInt > & unordered_set_VecInt_Result_Maintain   )
    {
​
        if(i_Layer != num_Whole_Layers )
        {
​
            for(int i = i_Work_In ; i < (( length_vec_Int_Wait_For_Use - num_Whole_Layers ) + i_Layer ) ; i++ )
            {
​
                int num_Temp_Cache_For_candidateElement = vec_Int_Wait_For_Use[i] ;
​
                num_Temp_Cache_For_Sum += num_Temp_Cache_For_candidateElement ;
​
                vec_Cache_NumSequence.push_back(num_Temp_Cache_For_candidateElement) ;
​
                // 减枝  
​
                if(num_Temp_Cache_For_Sum > target )
                {
                    num_Temp_Cache_For_Sum -= num_Temp_Cache_For_candidateElement ;
​
                    vec_Cache_NumSequence.pop_back() ;
​
                    continue ;
​
                }
​
                //
                fuction_Recursion_For_forLoop(num_Whole_Layers , ( i + 1 ) , length_vec_Int_Wait_For_Use , (i_Layer + 1 ) , vec_Cache_NumSequence ,vec_2_Dimention_For_Receive_And_Return , vec_Int_Wait_For_Use , num_Temp_Cache_For_Sum , target , unordered_set_VecInt_Result_Maintain ) ;
​
​
                num_Temp_Cache_For_Sum -= num_Temp_Cache_For_candidateElement ;
​
                vec_Cache_NumSequence.pop_back() ;
​
​
​
​
​
            }
​
​
​
​
        }
        else
        {
​
            for(int i = i_Work_In ; i < (( length_vec_Int_Wait_For_Use - num_Whole_Layers ) + i_Layer ) ; i++ )
            {
​
                int num_Temp_Cache_For_candidateElement = vec_Int_Wait_For_Use[i] ;
​
                num_Temp_Cache_For_Sum += num_Temp_Cache_For_candidateElement ;
​
                vec_Cache_NumSequence.push_back(num_Temp_Cache_For_candidateElement) ;
​
                //
​
                //cout<< "num_Temp_Cache_For_Sum = " << num_Temp_Cache_For_Sum << endl; 
​
                if(num_Temp_Cache_For_Sum == target )
                {
                    if(unordered_set_VecInt_Result_Maintain.find(vec_Cache_NumSequence) == unordered_set_VecInt_Result_Maintain.end())
                    {
​
                        vec_2_Dimention_For_Receive_And_Return.push_back(vec_Cache_NumSequence) ;
​
                        unordered_set_VecInt_Result_Maintain.insert(vec_Cache_NumSequence) ;
​
​
                    }
                    else
                    {
​
​
​
                    }
​
                    
​
                }
​
​
                num_Temp_Cache_For_Sum -= num_Temp_Cache_For_candidateElement ;
​
                vec_Cache_NumSequence.pop_back() ;
​
​
​
​
​
            }
​
​
​
​
​
        }
​
​
​
​
​
    }
​
​
};

Code 2 ( 处理 过程 中 进行 判断 去重 ):

class Solution {
public:
​
    struct Fuction_unordered_set_Hash_VectorInt
    {
        size_t operator()(const vector<int> & vec_In) const{
​
            std::size_t seed = 0 ;
            std::hash<int> hasher ;
​
​
            vector<int> vec_Process(vec_In) ;
​
            sort(vec_Process.begin(),vec_Process.end()) ;
​
            for(auto &address_i : vec_Process )
            //for(auto &address_i : vec_In )
            {
                seed ^= hasher(address_i) + 0x9e3779b9 + ( seed << 6 ) + ( seed >> 2 ) ;
​
​
            }
​
            return seed ;
​
​
​
        }
​
        
​
​
    };
​
​
​
    struct Fuction_unordered_set_Equal_VectorInt
    {
        bool operator()(const vector<int> & vec_1_In , const vector<int> & vec_2_In )const{
​
            vector<int> vec_1_Process (vec_1_In);
            vector<int> vec_2_Process (vec_2_In);
​
            sort(vec_1_Process.begin() , vec_1_Process.end()) ;
            sort(vec_2_Process.begin() , vec_2_Process.end()) ;
​
            for(int i = 0 ; i < vec_1_Process.size() ; i++ )
            {
                if(vec_1_Process[i] == vec_2_Process[i])
                {
​
                    continue ;
​
​
                }
                else
                {
​
                    return false ;
​
                }
​
​
            }
​
            return true ;
​
​
​
​
        }
​
​
    };
​
​
​
​
    vector<vector<int>> combinationSum2(vector<int>& candidates, int target) {
​
        int length_candidates = candidates.size() ;
​
        // vector<int> vec_Copy_candidates(candidates) ;
​
        // sort(vec_Copy_candidates.begin() , vec_Copy_candidates.end());
​
        // vector<int> vec_Int_Wait_For_Use ;
​
        vector<int> vec_Int_Wait_For_Use (candidates) ;
​
        sort(vec_Int_Wait_For_Use.begin() , vec_Int_Wait_For_Use.end() ) ;
​
        // for(int i = 0 ; i < vec_Copy_candidates.size() ; i++ )
        // {
        //     if((i + 1 ) < vec_Copy_candidates.size() && vec_Copy_candidates[i+1]!= vec_Copy_candidates[i])
        //     {
        //         vec_Int_Wait_For_Use.push_back(vec_Copy_candidates[i]);
​
​
        //     }
​
​
​
        // }
​
        int length_vec_Int_Wait_For_Use = vec_Int_Wait_For_Use.size() ;
​
​
​
        vector<int> vec_Cache_NumSequence ;             // 题目 要求 是 无序 级 
                                                        // 这里 是 有序  
​
        vector<vector<int>> vec_2_Dimention_For_Receive_And_Return ;
​
​
​
        int num_Temp_Cache_For_Sum = 0 ;
​
​
​
        unordered_set<vector<int> , Fuction_unordered_set_Hash_VectorInt , Fuction_unordered_set_Equal_VectorInt > unordered_set_VecInt_Result_Maintain ;
​
​
​
​
        for(int i = 1 ; i <= length_vec_Int_Wait_For_Use ; i++ )
        {
​
            //cout<<"i = "<<i <<endl;
​
            fuction_Recursion_For_forLoop(i , 0 , length_vec_Int_Wait_For_Use , 1 , vec_Cache_NumSequence , vec_2_Dimention_For_Receive_And_Return , vec_Int_Wait_For_Use , num_Temp_Cache_For_Sum , target , unordered_set_VecInt_Result_Maintain )  ;
​
​
        }
​
​
​
        return vec_2_Dimention_For_Receive_And_Return ;
​
​
​
​
        
    }
​
    void fuction_Recursion_For_forLoop(int num_Whole_Layers , int i_Work_In , int length_vec_Int_Wait_For_Use , int i_Layer , vector<int> & vec_Cache_NumSequence , vector<vector<int>> & vec_2_Dimention_For_Receive_And_Return , vector<int>& vec_Int_Wait_For_Use , int & num_Temp_Cache_For_Sum , int target , unordered_set<vector<int> , Fuction_unordered_set_Hash_VectorInt , Fuction_unordered_set_Equal_VectorInt > & unordered_set_VecInt_Result_Maintain   )
    {
        //cout<< " i_Layer = " << i_Layer <<endl ;
​
        if(i_Layer != num_Whole_Layers )
        {
​
            for(int i = i_Work_In ; i < (( length_vec_Int_Wait_For_Use - num_Whole_Layers ) + i_Layer ) ; i++ )
            {
                //cout<< " i _ inside = " << i <<endl ;
                int num_Temp_Cache_For_candidateElement = vec_Int_Wait_For_Use[i] ;
​
                //cout<< " num_Temp_Cache_For_candidateElement = " << num_Temp_Cache_For_candidateElement <<endl ;
​
                num_Temp_Cache_For_Sum += num_Temp_Cache_For_candidateElement ;
​
                vec_Cache_NumSequence.push_back(num_Temp_Cache_For_candidateElement) ;
​
                // 减枝  
​
                if(num_Temp_Cache_For_Sum > target )
                {
                    num_Temp_Cache_For_Sum -= num_Temp_Cache_For_candidateElement ;
​
                    vec_Cache_NumSequence.pop_back() ;
​
                    continue ;
​
                }
​
                //
                fuction_Recursion_For_forLoop(num_Whole_Layers , ( i + 1 ) , length_vec_Int_Wait_For_Use , (i_Layer + 1 ) , vec_Cache_NumSequence ,vec_2_Dimention_For_Receive_And_Return , vec_Int_Wait_For_Use , num_Temp_Cache_For_Sum , target , unordered_set_VecInt_Result_Maintain ) ;
​
​
                num_Temp_Cache_For_Sum -= num_Temp_Cache_For_candidateElement ;
​
                vec_Cache_NumSequence.pop_back() ;
​
​
                // 去除 重复 子集    
​
​
                if((i + 1 ) < (( length_vec_Int_Wait_For_Use - num_Whole_Layers ) + i_Layer ) && vec_Int_Wait_For_Use[i + 1 ] == num_Temp_Cache_For_candidateElement)
                {
                    cout<<22222222222<<endl;
                    while( (i + 1 ) < (( length_vec_Int_Wait_For_Use - num_Whole_Layers ) + i_Layer ) && vec_Int_Wait_For_Use[i + 1 ] == num_Temp_Cache_For_candidateElement )
                    {
​
                        i += 1 ;
​
​
                    }
​
                    //i -= 1 ; 
​
                    // 这是 到 最后 一个 一样 的 数 
                    // 而不是 下一个 值 的 数
​
​
                }
​
                // 对 后边 i++ 补正    
​
​
​
​
            }
​
​
​
​
        }
        else
        {
​
            for(int i = i_Work_In ; i < (( length_vec_Int_Wait_For_Use - num_Whole_Layers ) + i_Layer ) ; i++ )
            {
​
                int num_Temp_Cache_For_candidateElement = vec_Int_Wait_For_Use[i] ;
​
                //cout<< " num_Temp_Cache_For_candidateElement = " << num_Temp_Cache_For_candidateElement <<endl ;
​
                num_Temp_Cache_For_Sum += num_Temp_Cache_For_candidateElement ;
​
                vec_Cache_NumSequence.push_back(num_Temp_Cache_For_candidateElement) ;
​
                //
​
                //cout<< "num_Temp_Cache_For_Sum = " << num_Temp_Cache_For_Sum << endl; 
​
                if(num_Temp_Cache_For_Sum == target )
                {
                    //if(unordered_set_VecInt_Result_Maintain.find(vec_Cache_NumSequence) == unordered_set_VecInt_Result_Maintain.end())
                    //{
​
                        //vec_2_Dimention_For_Receive_And_Return.push_back(vec_Cache_NumSequence) ;
                    vec_2_Dimention_For_Receive_And_Return.push_back(vec_Cache_NumSequence) ;
​
                        //unordered_set_VecInt_Result_Maintain.insert(vec_Cache_NumSequence) ;
​
​
                    //}
                    //else
                    //{
​
​
​
                    //}
​
                    
​
                }
​
​
                num_Temp_Cache_For_Sum -= num_Temp_Cache_For_candidateElement ;
​
                vec_Cache_NumSequence.pop_back() ;
​
​
                // 去除 重复 子集    
​
                if((i + 1 ) < (( length_vec_Int_Wait_For_Use - num_Whole_Layers ) + i_Layer ) && vec_Int_Wait_For_Use[i + 1 ] == num_Temp_Cache_For_candidateElement)
                {
                    while( (i + 1 ) < (( length_vec_Int_Wait_For_Use - num_Whole_Layers ) + i_Layer ) && vec_Int_Wait_For_Use[i + 1 ] == num_Temp_Cache_For_candidateElement )
                    {
​
                        i += 1 ;
​
​
                    }
​
                    //i -= 1 ; 
​
​
                }
                
​
                // 对 后边 i++ 补正    
​
                // 对 未 跳 时  的  处理  
​
​
​
​
            }
​
​
​
​
​
        }
​
​
​
​
​
    }
​
​
};

131.分割回文串

题目地址 :

131. 分割回文串 - 力扣(LeetCode)

Code ( 特殊信息 的 分析 + 题目 需求 的 处理 + 结合 特殊信息 的 情况 Request xx Part 支持 ) :

class Solution {
public:
​
    struct Struct_Edge_Left_String_Edge_Right
    {
        int edge_Left ;
        string str_SubStr ;
        int edge_Right ;
​
​
​
    };
​
​
    vector<vector<string>> partition(string s) {
​
        int length_s = s.length() ;
​
​
        // 子串  在  这里  可以  重复    
​
            //      It ' s  different  
​
​
        // seed 位    /    发芽  的  位置    
​
​
​
        // 回文 串  信息  的  建立   
​
        vector<vector<Struct_Edge_Left_String_Edge_Right>> vec_Info_SubStr(length_s , vector<Struct_Edge_Left_String_Edge_Right>(0)) ;    
​
​
​
​
​
​
​
​
        // 奇 回文 串    
​
        // 这里 是  非  递归    
        for(int i = 0 ; i < length_s ; i++ )
        {
            int edge_Left = i ;
            int edge_Right = i ;
​
            string str_Temp_Cache = "";
​
            while(edge_Left >= 0 && edge_Right <= (length_s - 1 ) )
            {
                if(s[edge_Left] == s[edge_Right] )       // .equal()   or   ==     ?
                {                                    // 这里 是  C++  Use  ' == '
                    if(edge_Left == edge_Right )
                    {
                        str_Temp_Cache += s[edge_Left] ;
                    }
                    else 
                    {
                        str_Temp_Cache = s[edge_Left] + str_Temp_Cache + s[edge_Right] ;
​
​
                    }
​
​
                    Struct_Edge_Left_String_Edge_Right struct_Edge_Left_String_Edge_Right_Temp ;
​
                    struct_Edge_Left_String_Edge_Right_Temp.edge_Left = edge_Left ;
                    struct_Edge_Left_String_Edge_Right_Temp.edge_Right = edge_Right ;  
​
                    struct_Edge_Left_String_Edge_Right_Temp.str_SubStr = str_Temp_Cache ;
​
                    vec_Info_SubStr[edge_Left].push_back(struct_Edge_Left_String_Edge_Right_Temp) ;
​
                    //cout<<" struct_Edge_Left_String_Edge_Right_Temp.str_SubStr = " << struct_Edge_Left_String_Edge_Right_Temp.str_SubStr << endl ;
​
                    edge_Left -- ;
                    edge_Right ++ ;
​
​
​
                }
                else 
                {
​
​
                    break ;  
​
​
​
​
                }                          
​
​
​
​
            }
​
​
​
        }
​
​
​
​
        // 偶 回文 串    
        for(int i = 0 ; i < (length_s - 1 ) ; i++ )
        {
            int edge_Left = i ;
            int edge_Right = ( i + 1 ) ;
​
            string str_Temp_Cache = "";
​
            while(edge_Left >= 0 && edge_Right <= (length_s - 1 ) )
            {
                if(s[edge_Left] == s[edge_Right] )       // .equal()   or   ==     ?
                {                                    // 这里 是  C++  Use  ' == '
                    
                    str_Temp_Cache = s[edge_Left] + str_Temp_Cache + s[edge_Right] ;
​
​
                    Struct_Edge_Left_String_Edge_Right struct_Edge_Left_String_Edge_Right_Temp ;
​
                    struct_Edge_Left_String_Edge_Right_Temp.edge_Left = edge_Left ;
                    struct_Edge_Left_String_Edge_Right_Temp.edge_Right = edge_Right ;  
​
                    struct_Edge_Left_String_Edge_Right_Temp.str_SubStr = str_Temp_Cache ;
​
                    vec_Info_SubStr[edge_Left].push_back(struct_Edge_Left_String_Edge_Right_Temp) ;
​
                    //cout<<" struct_Edge_Left_String_Edge_Right_Temp.str_SubStr = " << struct_Edge_Left_String_Edge_Right_Temp.str_SubStr << endl ;
​
                    edge_Left -- ;
                    edge_Right ++ ;
​
​
​
                }
                else 
                {
​
​
                    break ;  
​
​
​
​
                }                          
​
​
​
​
            }
​
​
​
        }
​
​
​
        // 存到 以 左 起始点 为 下标 的 向量 中  ,  结构体 包含 : 左 起始 下标 , 字符串 信息 , 右 结束 下标 / 右 边界    
​
​
​
        vector< vector<string>> vec_2_Dimention_For_Receive_And_Return ;
​
        vector<string> vec_Str_For_Temp_Cache ;  
​
​
​
​
​
​
​
        // 尝试 使用 回文 字串  拼 出  “ 成 串  ”  /  “ 原本 整个 的 字符串    ”    
​
​
        fuction_Recursion_For_SpliceWholeStr( 0 , length_s , vec_Info_SubStr , vec_2_Dimention_For_Receive_And_Return , vec_Str_For_Temp_Cache )  ;
​
​
​
​
​
​
        return vec_2_Dimention_For_Receive_And_Return ;    
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
    }
​
​
                                            // string & str_Temp_Cache_For_ConstructWholeStr ,  
​
    void fuction_Recursion_For_SpliceWholeStr( int i_Edge_Left , int & length_s , vector<vector<Struct_Edge_Left_String_Edge_Right>> & vec_Info_SubStr , vector< vector<string>> & vec_2_Dimention_For_Receive_And_Return  , vector<string> & vec_Str_For_Temp_Cache  )
    {
        if(i_Edge_Left >= length_s)
        {
            return ;
        }
        else
        {
​
        }
​
        for(int i = 0 ; i < vec_Info_SubStr[i_Edge_Left].size() ; i++ )
        {
            
            if( ( vec_Info_SubStr[i_Edge_Left][i].edge_Right ) == (length_s - 1 ) )
            {
​
                vec_Str_For_Temp_Cache.push_back(vec_Info_SubStr[i_Edge_Left][i].str_SubStr ) ;  
​
​
                //
                vec_2_Dimention_For_Receive_And_Return.push_back(vec_Str_For_Temp_Cache) ;
​
​
​
                vec_Str_For_Temp_Cache.pop_back() ;  
​
​
​
​
​
​
​
            }
            else if( ( vec_Info_SubStr[i_Edge_Left][i].edge_Right ) > (length_s - 1 ))
            {
​
​
​
                
                continue ;
​
​
            }
            else if( ( vec_Info_SubStr[i_Edge_Left][i].edge_Right ) < (length_s - 1 ))  
            {
​
                //cout<<"vec_Info_SubStr[i_Edge_Left][i].str_SubStr = " << vec_Info_SubStr[i_Edge_Left][i].str_SubStr <<endl ; 
                vec_Str_For_Temp_Cache.push_back(vec_Info_SubStr[i_Edge_Left][i].str_SubStr ) ;  
​
​
                //
                                                                                    //  “ 下 一 个  ”
                fuction_Recursion_For_SpliceWholeStr( ( vec_Info_SubStr[i_Edge_Left][i].edge_Right + 1 ) ,  length_s , vec_Info_SubStr , vec_2_Dimention_For_Receive_And_Return  , vec_Str_For_Temp_Cache  ) ;
                
​
                vec_Str_For_Temp_Cache.pop_back() ;  
​
​
​
            }
​
​
​
​
        }
​
        
        
        
​
        
​
​
​
​
    }
​
​
​
​
​
​
};