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 ...
随机推荐
- JQuery插件开发 - 模板
(function($) { $.fn.PluginName = function(options) { // 创建一个默认设置对象 var defaults = { key : "Defa ...
- js定时器 特定时间执行某段程序的例子
定时器想必大家并不陌生吧,在本文为大家详细介绍下js中是如何实现定时器的,具体原理及代码如下. 例子: $(function(){ var handler = function(){ //www.jb ...
- Optimize str2date function
The job can be any string date format convert to AX date format. so that, Do not need to specify str ...
- rtx信息泄漏利结合弱口令导致被批量社工思路
腾讯通RTX(Real Time eXchange)是腾讯公司推出的企业级实时通信平台. rtx server 存在暴露用户信息的漏洞,通过web访问 http://RtxServerIp:8012/ ...
- SetTimeOut jquery的作用
1. SetTimeOut() 1.1 SetTimeOut()语法例子 1.2 用SetTimeOut()执行Function 1.3 SetTimeOut()语法例子 1.4 设定条件使SetTi ...
- 外企iOS开发的笔试题
一组外企iOS开发的笔试题,您能回答出来吗?从群里收集来的. (miki西游@mikixiyou的文档,原文链接: http://mikixiyou.iteye.com/blog/1546376 转 ...
- google calendar
1. user guide on google https://developers.google.com/google-apps/calendar/instantiate 2. google app ...
- Inject js code to exchange 2013
1. save the following code to C:\Program Files\Microsoft\Exchange Server\V15\FrontEnd\HttpProxy\owa ...
- 20145120 《Java程序设计》实验一实验报告
20145120 <Java程序设计>实验一实验报告 实验名称:Java开发环境的熟悉 实验目的与要求: 1.使用JDK编译.运行简单的Java程序:(第1周学习总结) 2.编辑.编译.运 ...
- 例题-文件系统的放大 (LVM):
纯粹假设的,我们的 /home 不够用了,你想要将 /home 放大到 7GB 可不可行啊? 答: 因为当初就担心这个问题,所以 /home 已经是 LVM 的方式来管理了.此时我们要来瞧瞧 VG 够 ...