杭电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 ...
随机推荐
- iBeacon在iPhone锁屏下有几率扫描不到蓝牙设备以及折中解决方案
前言: 这个问题的确困扰了很久,查了国内外各种论坛.社区,都没找到一个有效的解决办法. 所幸后来用一种折中的办法解决了,但也不是从技术根本上解决的,所以有解决的兄弟还望指导下. 正文如下: 一.需求描 ...
- 【AndroidStudio】关于SVN的相关配置简介
AndroidStudio 的SVN 安装和使用方法与我以前用的其他IDE 都有很大差别,感觉特麻烦,网上相关资料很少,貌似现在 Git 比较流行,之前有用过 github 但是他只能是开源项目免费, ...
- RF环境安装-mac-osx10.10-基础环境-安装指南
一.适用环境: mac系列,osx10.10,自带Python 二.简要步骤: 1. 安装pip,mac自带Python环境,所以我们改成安装pip 2. 安装wxPython,此处我下载的版本是wx ...
- excel 常用函数
1.统计整列唯一值的数量 =sumproduct(1/countif(offset(A1,,,COUNTA(A:A)),OFFSET(A1,,,COUNTA(A:A))))
- spring 加载多个资源文件
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.Prop ...
- [APP]如果你想反编译
反编译,主要用到两类工具,一个就是获取apk包的包名(appPackage)和类名(appActivity)的工具,其实就是反编译出java源代码,dex2jar和jd-gui:一个是将一个apk包反 ...
- .net导出不规则Excel
using Hamp.App.BLL; using Hamp.App.Model; using Hamp.App.Model.QualityManagement; using System; usin ...
- kali rolling 安装typecho
#1 apt-get install nginx php7.0 php7.0-mysql php7.0-gd php7.0-cgi php7.0-cli php7.0-curl php7.0-fpm ...
- Hadoop实践
1.将HDFS中的文本文件读取并以JSON格式转存到MongoDB时,报磁盘不足的异常. 实验室的5台计算机的存储空间都在500G以上,就目前存储的数据量来看,完全达不到磁盘接近饱和的状态.通过查看H ...
- Spire.XLS 在程序中直接打印excel
上代码 if (tbPrintSetBindingSource.Current == null) return; var item_TbPrintSet = tbPrintSetBindingSour ...