博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 3267 -- The Cow Lexicon
阅读量:5752 次
发布时间:2019-06-18

本文共 2919 字,大约阅读时间需要 9 分钟。

The Cow Lexicon
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 7987   Accepted: 3749

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 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 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 10browndcodwcowmilkwhiteblackbrownfarmer

Sample Output

2 题目大意:最少删掉多少个字符使之能与下面的字典匹配。 思路:动态规划解决.倒着推。dp[i]表示:第i个字符到最后 至少删除几个字符。    则有: dp[i] = dp[i+1] + 1   匹配不到       dp[i] = min(dp[i], dp[Tpoint] + Tpoint - i - len) 匹配到       解释:Tpoint是在主串中的位置。len 是当前单词的长度。       dp[Tpoint] 表示Tpoitn到最后应删除的字符数。 Tpoing-i-len 表示i到Tpoint 应删除的字符数。
1 /*====================================================================== 2  *           Author :   kevin 3  *         Filename :   TheCowLexicon.cpp 4  *       Creat time :   2014-07-12 15:06 5  *      Description : 6 ========================================================================*/ 7 #include 
8 #include
9 #include
10 #include
11 #include
12 #include
13 #define clr(a,b) memset(a,b,sizeof(a))14 #define N 60515 using namespace std;16 char str[N][N];17 char T[N];18 int dp[N];19 int main(int argc,char *argv[])20 {21 int n,m;22 while(scanf("%d%d",&n,&m)!=EOF){23 getchar();24 gets(T);25 for(int i = 0; i < n; i++){26 scanf("%s",str[i]);27 getchar();28 }29 clr(dp,0);30 for(int i = m-1; i >= 0; i--){31 dp[i] = dp[i+1] + 1;32 for(int j = 0; j < n; j++){33 int len = strlen(str[j]);34 if(m-i >= len && str[j][0] == T[i]){35 int strpoint = 0;36 for(int Tpoint = i; Tpoint < m;){37 if(str[j][strpoint] == T[Tpoint++]){38 strpoint++;39 }40 if(strpoint == len){41 dp[i] = min(dp[i],dp[Tpoint] + Tpoint-i-len);42 break;43 }44 }45 }46 }47 }48 printf("%d\n",dp[0]);49 }50 return 0;51 }
View Code

 

转载于:https://www.cnblogs.com/ubuntu-kevin/p/3878286.html

你可能感兴趣的文章
AIX:物理卷及有关概念
查看>>
我的友情链接
查看>>
Centos6.6安装选包及基础场景说明
查看>>
java基础面试题-1
查看>>
深克隆与序列化效率的比较
查看>>
lamp+nginx代理+discuz+wordpress+phpmyadmin搭建一
查看>>
nagios监控使用139邮箱报警
查看>>
Windows Phone 7 中各种Task解说(启动器与选择器)
查看>>
罗森伯格助力2011年中国智能建筑技术发展应用论坛哈尔滨站
查看>>
网络割接
查看>>
windows server 2016 活动目录(二)
查看>>
openstack G版 修改vm的flavor级别
查看>>
python_控制台输出带颜色的文字方法
查看>>
java泛型中特殊符号的含义
查看>>
一秒 解决 ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql 问题
查看>>
Android组件化最佳实践 ARetrofit原理
查看>>
舍弃浮躁, 50条重要的C++学习建议
查看>>
同步手绘板——将View的内容映射成Bitmap转图片导出
查看>>
【Android游戏开发之十】(优化处理)详细剖析Android Traceview 效率检视工具!分析程序运行速度!并讲解两种创建SDcard方式!...
查看>>
微信小程序之wx.navigateback往回携带参数
查看>>