POJ 3267 The Cow Lexicon

Source: Internet
Author: User

The Cow Lexicon
Time Limit: 2000 MS Memory Limit: 65536 K
Total Submissions: 6548 Accepted: 3021
Description

Few know that the cows have their own dictionary with W (1 ≤ W ≤ 600) words, each containing no more 25 of the characters 'A '.. 'Z '. their cowmunication system, based on mooing, is not very accurate; sometimes they hear words that do not make any sense. for instance, Bessie once received a message that said "browndcodw ". as it turns out, the intended message was "browncow" and the two letter "d" s were noise from other parts of the barnyard.

The cows want you to help them decipher a received ed message (also containing only characters in the range 'A '.. 'Z') of length L (2 ≤ L ≤300) characters that is a bit garbled. in particle, they know that the message has some extra letters, and they want you to determine the smallest number of letters that must be removed to make the message a sequence of words from the dictionary.

Input

Line 1: Two space-separated integers, respectively: W and L
Line 2: L characters (followed by a newline, of course): the received message
Lines 3. W + 2: The cows 'dictionary, one word per line
Output

Line 1: a single integer that is the smallest number of characters that need to be removed to make the message a sequence of dictionary words.
Sample Input

6 10
Browndcodw
Cow
Milk
White
Black
Brown
Farmer
Sample Output

2
Source

USACO 2007 February Silver
I didn't have any idea when I was doing this. I felt that I was using dp but I wouldn't do it. So I took a look at the problem-solving report.
I think this is quite good.
# Include <iostream>
# Include <string. h>
Using namespace std;
Int dp [400];
String s1 [610];
String s2;
Int min1;
Int main ()
{
Int I, j, n, m, s, t;
Int len, l, x, y;
Cin> n> len;
Cin> s2;
For (I = 1; I <= n; I ++)
{
Cin> s1 [I];
}
Dp [len] = 0;
For (I = len-1; I> = 0; I --)
{
Dp [I] = dp [I + 1] + 1;
For (j = 1; j <= n; j ++)
{
L = s1 [j]. size ();
If (l <= (len-I) & s2 [I] = s1 [j] [0])
{
For (x = I, y = 0; x <= len-1; x ++)
{
If (s2 [x] = s1 [j] [y])
{
Y ++;
}
If (y = l)
{
If (dp [I]> (dp [x + 1] + (x + 1)-I-l ))
{
Dp [I] = (dp [x + 1] + (x + 1)-I-l );
}
}
}
}
}
}
Cout <dp [0] <endl;
Return 0;
}

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.