"POJ 3267" the Cow Lexicon

Source: Internet
Author: User

"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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.