Description
Few know that the cows has their own dictionary with W (1≤w≤600) words, each containing no more than the characters ' A ' ... ' Z '. Their cowmunication system, based on mooing, was not very accurate; Sometimes they hear words. For instance, Bessie once received a message that said "Browndcodw". As it turns out, the intended message is "Browncow" and the "D" s were noise from other parts of the barnyard.
The cows want you-to-help them decipher a received message (also-containing only characters in the range ' a ' ... ' Z ') of length L (2≤l≤300) characters that is a bit garbled. In particular, they know that the message had some extra letters, and they want you to determine the smallest number of Le Tters that must is 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 So is the smallest number of characters so need to being removed to make the message a SE Quence of dictionary words.
Sample Input
6
browndcodw
cow milk
white
black
Brown
Farmer
Sample Output
2
/*
There are 600 of words. The given string length is capped at 300;
Do it from the back. If the character can match the first letter of the word. So just keep looking down. T represents a text string, and P denotes the word. When T[i]!=p[j], you have to match t[i+1] and p[j]. And so on, when the end is because the access to T end, then do not delete. If it is access to P end.
Then we have to make comparisons. */#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <
Algorithm> using namespace std;
String a[608];
int dp[308];
inline int min (int a,int b) {return a>b?b:a;} int main () {int n,len;
Char t[308];
while (scanf ("%d%d", &n,&len) ==2) {cin>>t;
for (int i=1;i<=n;i++) {cin>>a[i];
} sort (a,a+n);
Memset (Dp,0,sizeof (DP));
for (int i=len-1;i>=0;i--) {dp[i]=dp[i+1]+1;
for (int j=1;j<=n;j++) {if (A[j][0]==t[i]) {int len1=a[j].size ();
int m=i;
for (int k=1;k<len1;k++) {m++;
if (M>=len) break;
while (T[m]!=a[j][k]) {m++;
if (M>=len) {break; }} if (M<len&&t[m]==a[j][k]) {if (k==len1-1) {dp[i]=min (dp[i],dp[m+1]+M-I+1-LEN1);
}}}}}} printf ("%d\n", dp[0]);
} return 0;
}