# Include <iostream> <br/> # include <string> <br/> using namespace STD; <br/> int V [302]; <br/> char s [600] [27]; <br/> char word [302]; <br/> int Len [600]; <br/> int N, l; <br/> int main () <br/>{< br/> scanf ("% d", & N, & L ); </P> <p> scanf ("% s", & Word); <br/> for (INT I = 0; I <n; ++ I) <br/>{< br/> scanf ("% s", & S [I]); <br/> Len [I] = strlen (s [I]); <br/>}</P> <p> V [0] = 1; <br/> for (INT I = 0; I <n; ++ I) <br/> If (LEN [I] = 1 & word [0] = s [I] [0]) <br/> V [0] = 0; </P> <p> for (INT I = 1; I <L; ++ I) <br/> {<br/> int min = V [I-1] + 1; <br/> for (Int J = 0; j <n; ++ J) <br/> if (I + 1> = Len [J] & S [J] [Len [J]-1] = word [I]) <br/> {<br/> int Index = I-1; <br/> int Pos = Len [J]-2; <br/> while (index >=0 & Pos> = 0) <br/> {<br/> If (s [J] [POS] = word [Index]) <br/> pos --; <br/> index --; <br/>}< br/> If (Pos <0 & V [Index] + I-index-len [J] <min) <br/> min = V [Index] + I-index-len [J]; <br/>}< br/> V [I] = min; <br/>}</P> <p> printf ("% d/N", V [L-1]); <br/> return 0; <br/>}</P> <p>/* <br/> // learned: <br/> if this question matches each word from the back to the back, the efficiency will be much higher. <br/> The following TLE solution is because the efficiency of matching each word for each num [k + 1, I] is very low. </P> <p> yjs: <br/> for (Int J = 0; j <n; ++ J) <br/> vs <br/> for (int K = 0; k <I; ++ K) & for (INT I = 0; I <N; ++ I) </P> <p> the state transition equation is V [I] = min {v [K], num [k + 1, i]} </P> <p> problem: 3267 User: xiaofengsheng <br/> memory: 412 K time: 63 MS <br/> language: G ++ result: accepted <br/> */</P> <p>/* # include <iostream> <br/> # include <string> <br/> using namespace STD; <br/> int V [302]; <br/> char s [600] [27]; <br/> char word [302]; <br/> int Len [600]; <br/> int n, l; <br/> // v [I] = min {v [K], num [k + 1, I]} (-1 <= k <= i-1); </P> <p> inline int F (INT M, int N) <br/>{< br/> int min = 100000; <br/> bool flag = false; <br/> for (INT I = 0; I <N; ++ I) <br/>{< br/> int Pos = 0; <br/> int Index = m; <br/> while (index <= N & Pos <Len [I]) <br/> {<br/> If (s [I] [POS] = word [Index]) <br/> POS ++; <br/> index ++; <br/>}< br/> If (Pos = Len [I] & N-M + 1-pos <min) <br/>{< br/> min = N-M + 1-pos; <br/> flag = true; <br/>}< br/> If (FLAG) <br/> return min; <br/> else <br/> return N-m + 1; <br/>}</P> <p> int main () <br/>{< br/> scanf ("% d", & N, & L); </P> <p> scanf ("% s ", & Word); <br/> for (INT I = 0; I <n; ++ I) <br/> {<br/> scanf ("% s ", & S [I]); <br/> Len [I] = strlen (s [I]); <br/>}</P> <p> for (INT I = 0; I <n; ++ I) <br/> puts (s [I]); </P> <p> V [0] = 1; <br/> for (INT I = 0; I <n; ++ I) <br/> If (LEN [I] = 1 & word [0] = s [I] [0]) <br/> V [0] = 0; </P> <p> for (INT I = 1; I <L; ++ I) <br/> {<br/> int min = f (0, i); <br/> for (int K = 0; k <I; ++ K) <br/> {<br/> int ret = f (k + 1, i); <br/> If (V [k] + RET <min) <br/> min = V [k] + ret; <br/>}< br/> V [I] = min; <br/>}</P> <p> printf ("% d/N ", V [L-1]); <br/> return 0; <br/>}< br/> */<br/>