"POJ 3267" the Cow Lexicon
The training plan put the problem in the topo .... And then I just died staring at the topo algorithm for a week (during which there were three life disturbances ...). Big things test high number of test with the mold electrical examination ....) What's not to say ... On the DP code ..... Yes, it's a dp!. DP of red fruit fruit. What about it? Study the topo algorithm in a silly way ... The results were not studied.
Test instructions is a dictionary of strings and M words, and a minimum number of letters can be removed to make the string a string that consists of the first link of several words in the dictionary.
DP idea is good. The subscript of the DP array is to traverse the starting point of the string and then intercept the string traversal from the tail to find the minimum number of deleted letters required. Each time you iterate through all the dictionary words, find the maximum number of letters to delete using the word and then keep DP .... It's a little bad, look at the code.
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <string>using namespace STD;Charstr[301],ch[ -][ -];intdp[301],len[ -];intMain () {intW,l,i,j,cnt,p;scanf("%d%d", &w,&l);scanf('%s ', str); for(i =0; i < W; ++i) {scanf('%s ', Ch[i]); Len[i] =strlen(Ch[i]); } dp[l-1] =0; for(i = l-1; I >=0; -I.) {Dp[i] = dp[i+1]+1; for(j =0; J < W; ++J) {if(Len[j] > L-i | | str[i]! = ch[j][0])Continue; CNT =0; p = i; while(P < L) {if(ch[j][cnt] = = str[p++]) cnt++;if(cnt = = Len[j]) {Dp[i] = min (dp[i],dp[p]+p-i-len[j]); Break; } } } }printf("%d\n", dp[0]);return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
"POJ 3267" the Cow Lexicon