POJ3267 The Cow Lexicon(DP+删词)
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 9041 | Accepted: 4293 |
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 2: L characters (followed by a newline, of
course): the received message
Lines 3..W+2: The cows' dictionary, one
word per line
Output
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
dp[i]表示message从i位置开始需要删除几个字母
dp[i] = dp[i + 1] + 1 // 表示它在i位置并不匹配,删除i位置的字母,
dp[i] = min(dp[i],dp[i + len + t] + t) //对于长度为len的单词,从i开始需要删除t个字母才能完全匹配,i+len+t表示匹配后的下一个,dp[i+len+t]就是匹配成功下一个位置的需要删除的字母数
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
char dic[][];
char mess[ + ];
int w,l,dp[];
int DP(int x, int len, int y)
{
int j = , tot = ;
while(x <= l)
{
if(mess[x] == dic[y][j])
j++;
else
tot++;
if(j == len + ) // j==len的时候还没结束,还要匹配len位置,len是最后一个
return tot;
x++;
}
return -;
}
int main()
{
while(scanf("%d%d", &w, &l) != EOF)
{
scanf("%s", mess + );
for(int i = ; i <= w; i++)
{
scanf("%s", dic[i] + );
}
memset(dp, , sizeof(dp));
for(int i = l; i > ; i--)
{
dp[i] = dp[i + ] + ;
for(int j = ; j <= w; j++)
{
int len = strlen(dic[j] + );
int t = DP(i, len, j);
if(t != -)
{
dp[i] = min(dp[i], dp[i + len + t] + t);
}
}
}
printf("%d\n", dp[]);
}
return ;
}
POJ3267 The Cow Lexicon(DP+删词)的更多相关文章
- POJ3267 The Cow Lexicon(dp)
题目链接. 分析: dp[i]表示母串从第i位起始的后缀所对应的最少去掉字母数. dp[i] = min(dp[i+res]+res-strlen(pa[j])); 其中res 为从第 i 位开始匹配 ...
- POJ3267——The Cow Lexicon(动态规划)
The Cow Lexicon DescriptionFew know that the cows have their own dictionary with W (1 ≤ W ≤ 600) wor ...
- poj3267--The Cow Lexicon(dp:字符串组合)
The Cow Lexicon Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8211 Accepted: 3864 D ...
- POJ 3267-The Cow Lexicon(DP)
The Cow Lexicon Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8252 Accepted: 3888 D ...
- USACO 2007 February Silver The Cow Lexicon /// DP oj24258
题目大意: 输入w,l: w是接下来的字典内的单词个数,l为目标字符串长度 输入目标字符串 接下来w行,输入字典内的各个单词 输出目标字符串最少删除多少个字母就能变成只由字典内的单词组成的字符串 Sa ...
- The Cow Lexicon(dp)
Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7290 Accepted: 3409 Description Few k ...
- POJ 3267:The Cow Lexicon(DP)
http://poj.org/problem?id=3267 The Cow Lexicon Time Limit: 2000MS Memory Limit: 65536K Total Submi ...
- POJ 3267:The Cow Lexicon 字符串匹配dp
The Cow Lexicon Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8905 Accepted: 4228 D ...
- BZOJ 1633: [Usaco2007 Feb]The Cow Lexicon 牛的词典
题目 1633: [Usaco2007 Feb]The Cow Lexicon 牛的词典 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 401 Solv ...
随机推荐
- 使用CuteSlider做网站炫酷的幻灯片
cuteSlider 1.预览 官网:http://www.cuteslider.com/ 应用:http://www.dutphonelab.org/ 2.资料 文档:http://pan.baid ...
- MAC中设置android adb环境变量
1.找到android sdk的本地路径, adb命令在platform-tool下面,记为XXXX 我的路径是(/Applications/eclipse/android-sdk-mac_x86/p ...
- AVPlayer的使用本地视频
1引入AVFoundation.framework框架 2引入头文件<AVFoundation/AVFoundation.h>,并拖入需要播放的视频文件 代码如下: 自定义播放的View, ...
- edgesForExtendedLayout、extendedLayoutIncludesOpaqueBars、automaticallyAdjustsScrollViewInsets属性详解 )——转载
edgesForExtendedLayout: 在ios7适配中,布局问题是一个很头痛也很重要的问题,因为在ios7中viewController使用了全屏布局的方式,也就是说导航栏和状态栏都是不占实 ...
- 关于ARP攻击的原理以及在Kali Linux环境下的实现
关于ARP攻击的原理以及在Kali Linux环境下的实现 全文摘要 本文讲述内容分为两部分,前半部分讲述ARP协议及ARP攻击原理,后半部分讲述在Kali Linux环境下如何实现ARP攻击以及AR ...
- 零散知识记录-一个MQ问题
[背景]我有一项零散工作:维护大部门的一台测试公用MQ服务器.当大部分MQ被建立起来,编写了维护手册,大家都按照规程来后,就基本上没有再动过它了.周五有同学跟我反映登录不进去了,周日花了1个小时来解决 ...
- 证书与keytool
证书的来源与使用: 对数据进行签名是我们在网络中最常见的安全操作.签名有双重作用,作用一就是保证数据的完整性,证明数据并非伪造,而且在传输的过程中没有被篡改,作用二就是防止数据的发布者否认其发布了该数 ...
- java并发:线程同步机制之Lock
一.初识Lock Lock是一个接口,提供了无条件的.可轮询的.定时的.可中断的锁获取操作,所有加锁和解锁的方法都是显式的,其包路径是:java.util.concurrent.locks.Lock, ...
- 『设计』Slithice 分布式架构设计-支持一体式开发,分布式发布
项目原因: 参与过各种 分布式项目,有 Socket,Remoting,WCF,当然还有最常用的可以跨平台的 WebService. 分布式编码的时间浪费: 但是,无一例外的,开发分布式程序的开发遵循 ...
- Android将应用程序的崩溃信息如何保存到本地文件,并上传服务器
导语:最近实在是太忙了,没有怎么更新公众号,也没有怎么认真去写一些内容,在这里先给关注我的朋友说一声抱歉,可能在接下来的一段时间,还是很忙,但是我会争取抽空多分享一下技术文章,给大家看,共同进步,也希 ...