[ダイナミックプログラミング] leetcode 139ワードブレイク

問題:https://leetcode.com/problems/word-break/

       問題のパーティションタイプ。

クラス解決{
 パブリックブール wordBreak(ストリング S、ベクトル< ストリング >&wordDict){
         int型 N = s.size()。
        unordered_set < 文字列 > 辞書。
        以下のためにint型 i = 0 ; iはwordDict.size()<; I ++のを
        { 
            dict.insert(wordDict [I])。
        } 
        ベクトル < ブール > DP(N + 1)。
        DP [ 0 ] = ;
        以下のためにint型 i = 0 ; iがn <; iは++ 
        { 
            ためのint型 J = 0 ; J <= I; J ++ 
            { 
                int型 LEN = I - J + 1 文字列の単語= s.substr(J、LEN);
       //          coutの<<単語<<てendl; 
                場合(!dict.find(ワード)= dict.end())
                { 
                    場合(DP [J])
                    { 
                        DP [I + 1 ] = 破ります; 
                    } 
                } 
            } 
        } 
        戻りDP [n]は、
    } 
}。

 

おすすめ

転載: www.cnblogs.com/fish1996/p/11330212.html