杭电15题 The Cow Lexicon
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.
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath> using namespace std; int main()
{
int dp[]={};
string str[];
int w,l;
cin>>w>>l;//输入w和l
string s;
cin>>s;//输入待检测的字符串;
int i;
for(i=;i<w;i++)
cin>>str[i];
int j;int k;
dp[l]=;
int right=;
int len;
for(i=l-;i>=;i--)
{
dp[i]=dp[i+]+;
for(j=;j<w;j++)
{
if(s[i]==str[j][])
{//进行匹配;
k=i;
len=str[j].length();
right=;
while(right<len&&k<l)
{
if(s[k]==str[j][right]){right++;}
k++;
if(right==len)
{
dp[i]=min(dp[i],dp[k]+k-i-len);
break;
}
}
}
}
}
cout<<dp[]<<endl;
return ;
}
杭电15题 The Cow Lexicon的更多相关文章
- 高手看了,感觉惨不忍睹——关于“【ACM】杭电ACM题一直WA求高手看看代码”
按 被中科大软件学院二年级研究生 HCOONa 骂为“误人子弟”之后(见:<中科大的那位,敢更不要脸点么?> ),继续“误人子弟”. 问题: 题目:(感谢 王爱学志 网友对题目给出的翻译) ...
- Help Johnny-(类似杭电acm3568题)
Help Johnny(类似杭电3568题) Description Poor Johnny is so busy this term. His tutor threw lots of hard pr ...
- 杭电oj2093题,Java版
杭电2093题,Java版 虽然不难但很麻烦. import java.util.ArrayList; import java.util.Collections; import java.util.L ...
- acm入门 杭电1001题 有关溢出的考虑
最近在尝试做acm试题,刚刚是1001题就把我困住了,这是题目: Problem Description In this problem, your task is to calculate SUM( ...
- 杭电dp题集,附链接还有解题报告!!!!!
Robberies 点击打开链接 背包;第一次做的时候把概率当做背包(放大100000倍化为整数):在此范围内最多能抢多少钱 最脑残的是把总的概率以为是抢N家银行的概率之和- 把状态转移方程写成了f ...
- 杭电ACM题单
杭电acm题目分类版本1 1002 简单的大数 1003 DP经典问题,最大连续子段和 1004 简单题 1005 找规律(循环点) 1006 感觉有点BT的题,我到现在还没过 1007 经典问题,最 ...
- 杭电的题,输出格式卡的很严。HDU 1716 排列2
题很简单,一开始写代码,是用整数的格式写的,怎么跑都不对,就以为算法错了,去看大佬们的算法STL全排列:next_permutation(); 又双叒叕写了好几遍,PE了将近次,直到跑了大佬代码发现, ...
- 杭电60题--part 1 HDU1003 Max Sum(DP 动态规划)
最近想学DP,锻炼思维,记录一下自己踩到的坑,来写一波详细的结题报告,持续更新. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1003 Problem ...
- 杭电21题 Palindrome
Problem Description A palindrome is a symmetrical string, that is, a string read identically from le ...
随机推荐
- html基础及心得
html开始 <adress></adress>斜体(地址) <em><em>斜体(表示强调) <code></code>插入一 ...
- 搭建gitbook环境
1.官网下载安装nodejs,安装完成后使用终端输入node -v,用cmd命令窗口查看是否安装成功:如下图所示: 2.在cmd命令窗口中输入:npm install -g cnpm -registr ...
- Webgis中关于Openlayers入门使用(一)安装及生成基本地图
一.WebGis项目中使用的版本2.12 下载地址:https://github.com/openlayers/ol2/releases https://github.com/openlayers/o ...
- Font-Awesome IIS下不显示问题
解决方法: 在IIS设置中添加一个IMME fileExtension: .woff mimeType:application/x-font-woff
- sqlserver判断字符串是否是数字
sql2005有个函数ISNUMERIC(expression)函数:当expression为数字时,返回1,否则返回0.这只是一个菜鸟级的解决办法,大多数情况比较奏效. eg: ') --结果为1 ...
- foreach 循环的应用传值
$arr=array(1,5,8,8,9);foreach ($arr as $key => $value) { //这里可以一边改外面$arr的值一边下一步循环 $value=++$value ...
- centos7下用yum安装mysql5.7
1.安装mysql源 下载地址:http://dev.mysql.com/downloads/repo/yum/ 下载之后用yum安装:yum localinstall -y xx.noarch.rp ...
- 根据ClassName获取元素节点
功能描述: 通过ClassName获取元素节点,并解决兼容性问题 实现效果: 编码思路: 利用getElementsByTagName选出所有元素,再根据ClassName条件进行筛选 代码示例:
- C#之委托(函数参数传递)【转】
原文:http://blog.csdn.net/wangdan199112/article/details/18796527 在学委托这块儿的时候,函数参数这块不是很理解,于是针对一个例子做了深入的理 ...
- spring的@Transactional注解详细用法
概述 事务管理对于企业应用来说是至关重要的,即使出现异常情况,它也可以保证数据的一致性.Spring Framework对事务管理提供了一致的抽象,其特点如下: 为不同的事务API提供一致的编程模型, ...