POJ3267The Cow Lexicon
http://poj.org/problem?id=3267
题意 : 给你一个message,是给定字符串,然后再给你字典,让你将message与字典中的单词进行匹配,输出要删掉多少字母。
思路 : 动态规划问题,不仅要找对公式,还要注意一些细节问题
样例解释 : 6是字典里有6个单词,10是给定的字符串的长度,给定的字符串可以与下面的brown和cow匹配,但要删掉两个字母
6 10
browndcodw
cow
milk
white
black
brown
farmer
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
using namespace std ;
int main()
{
int W,L,len ;
string mess,dic[];
cin>>W>>L ;
int dp[] ;
cin>>mess ;
for(int i = ; i < W ; i++)
cin>>dic[i] ;
dp[L] = ;//dp[i]代表着从i到L所要删除的字符个数
for(int i = L- ; i >= ; i--)//从message中倒着找
{
dp[i] = dp[i+]+ ;//先将最坏的可能存入数组
for(int j = ; j < W ; j++)
{
len = dic[j].length() ;
if(len <= L-i && dic[j][] == mess[i])//字典里的某个单词的长度要小于你进行匹配的一部分message的长度
{
int me = i,di = ;
while(me < L)
{
if(dic[j][di] == mess[me++])
{
di++ ;
}
if(di == len)
{
dp[i] = min(dp[i],dp[me]+me-i-len) ;//dp[me]代表着从me到L要删除的字符的个数,me-i代表匹配过程中,从位置i到me的区间长度,再减去单词长度,即可得则得到从i到me所删除的字符数
break ;
}
}
}
}
}
cout<<dp[]<<endl ;
return ;
}
POJ3267The Cow Lexicon的更多相关文章
- poj3267--The Cow Lexicon(dp:字符串组合)
The Cow Lexicon Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8211 Accepted: 3864 D ...
- POJ3267 The Cow Lexicon(DP+删词)
The Cow Lexicon Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9041 Accepted: 4293 D ...
- POJ 3267 The Cow Lexicon
又见面了,还是原来的配方,还是熟悉的DP....直接秒了... The Cow Lexicon Time Limit: 2000MS Memory Limit: 65536K Total Submis ...
- POJ 3267:The Cow Lexicon(DP)
http://poj.org/problem?id=3267 The Cow Lexicon Time Limit: 2000MS Memory Limit: 65536K Total Submi ...
- The Cow Lexicon
The Cow Lexicon Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8815 Accepted: 4162 Descr ...
- HDOJ-三部曲-1015-The Cow Lexicon
The Cow Lexicon Time Limit : 4000/2000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) To ...
- POJ3267——The Cow Lexicon(动态规划)
The Cow Lexicon DescriptionFew know that the cows have their own dictionary with W (1 ≤ W ≤ 600) wor ...
- BZOJ 1633: [Usaco2007 Feb]The Cow Lexicon 牛的词典
题目 1633: [Usaco2007 Feb]The Cow Lexicon 牛的词典 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 401 Solv ...
- POJ 3267-The Cow Lexicon(DP)
The Cow Lexicon Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8252 Accepted: 3888 D ...
随机推荐
- DB2&&oracle-培训内容
DB2 1 Data Sharing架构,高可用 2 DB2的对象主要有以下几类:database,storage group, Tablspace, indexspace, table,index ...
- 在Java中怎样把数组转换为ArrayList?
翻译自:How to Convert Array to ArrayList in Java? 本文分析了Stack Overflow上最热门的的一个问题的答案,提问者获得了很多声望点,使得他得到了在S ...
- javascript框架库API入口
underscorejs : http://learning.github.io/underscore/
- linux服务器修改ssh默认22端口方法
1.登录服务器,打开sshd_config文件 # vim /etc/ssh/sshd_config 2.找到#Port 22,默认是注释掉的,先把前面的#号去掉,再插入一行设置成你想要的端口号,注意 ...
- 分享:mysql 随机查询数据
在mysql中查询5条不重复的数据,使用以下: 1 SELECT * FROM `table` ORDER BY RAND() LIMIT 5 就可以了.但是真正测试一下才发现这样效率非常低.一个1 ...
- 用nodejs删除mongodb中ObjectId类型数据
mongodb中"_id"下面有个ObjectId类型的数据,想通过这个数据把整个对像删除,费了半天劲终于搞定费话少说上代码 module.exports = function ( ...
- opencv学习笔记(04)——ROI
ROI的用法:1.直接相加:2.掩码法 #include <opencv2\highgui\highgui.hpp> #include <opencv2\imgproc\imgpro ...
- awk简明教程
我在这里的教程并不想面面俱到,全是示例,基本无废话. 我只想达到两个目的: 1)你可以在乘坐公交地铁上下班,或是在坐马桶拉大便时读完(保证是一泡大便的工夫). 2)我只想让这篇博文像一个火辣的脱衣舞女 ...
- thinkphp中curl的使用,常用于接口
/lib/action/PublicAction.class.php class PublicAction extends Action{ //curl,返回数组 public function ge ...
- owin 中间件 katana 如何解密cookie
.NET MVC5 默认的用户登录组件是AspNet.Identity ,支持owin,并且微软自己实现的一套owin 中间件叫 katana 补充一下 katana项目源码地址:https://ka ...