Problem 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 1: Two space-separated integers, respectively: W and L 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
Line 1: a single integer that is the smallest number 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
PKU
题意:给定一个字符串检查最大数量的匹配单词是多少;
思路:
AC代码:
 #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的更多相关文章

  1. 高手看了,感觉惨不忍睹——关于“【ACM】杭电ACM题一直WA求高手看看代码”

    按 被中科大软件学院二年级研究生 HCOONa 骂为“误人子弟”之后(见:<中科大的那位,敢更不要脸点么?> ),继续“误人子弟”. 问题: 题目:(感谢 王爱学志 网友对题目给出的翻译) ...

  2. Help Johnny-(类似杭电acm3568题)

    Help Johnny(类似杭电3568题) Description Poor Johnny is so busy this term. His tutor threw lots of hard pr ...

  3. 杭电oj2093题,Java版

    杭电2093题,Java版 虽然不难但很麻烦. import java.util.ArrayList; import java.util.Collections; import java.util.L ...

  4. acm入门 杭电1001题 有关溢出的考虑

    最近在尝试做acm试题,刚刚是1001题就把我困住了,这是题目: Problem Description In this problem, your task is to calculate SUM( ...

  5. 杭电dp题集,附链接还有解题报告!!!!!

    Robberies 点击打开链接 背包;第一次做的时候把概率当做背包(放大100000倍化为整数):在此范围内最多能抢多少钱  最脑残的是把总的概率以为是抢N家银行的概率之和- 把状态转移方程写成了f ...

  6. 杭电ACM题单

    杭电acm题目分类版本1 1002 简单的大数 1003 DP经典问题,最大连续子段和 1004 简单题 1005 找规律(循环点) 1006 感觉有点BT的题,我到现在还没过 1007 经典问题,最 ...

  7. 杭电的题,输出格式卡的很严。HDU 1716 排列2

    题很简单,一开始写代码,是用整数的格式写的,怎么跑都不对,就以为算法错了,去看大佬们的算法STL全排列:next_permutation(); 又双叒叕写了好几遍,PE了将近次,直到跑了大佬代码发现, ...

  8. 杭电60题--part 1 HDU1003 Max Sum(DP 动态规划)

    最近想学DP,锻炼思维,记录一下自己踩到的坑,来写一波详细的结题报告,持续更新. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1003 Problem ...

  9. 杭电21题 Palindrome

    Problem Description A palindrome is a symmetrical string, that is, a string read identically from le ...

随机推荐

  1. 转:iOS程序main函数之前发生了什么

    原文地址:http://blog.sunnyxx.com/2014/08/30/objc-pre-main/ 我是前言 一个iOS app的main()函数位于main.m中,这是我们熟知的程序入口. ...

  2. Java的URL来下载网页源码

    import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.IOException; impor ...

  3. GrowingIO 2016 数据驱动增长大会—— 一起做增长英雄

    GrowingIO 2016 数据驱动增长大会,首次聚齐了增长黑客之父 Sean Ellis .世界前十位前沿数据科学家张溪梦等数十位中美顶尖增长实践者: 链家.点融网.Camera360.量化派.北 ...

  4. [SOJ] 商人的宣传

    Description Bruce是K国的商人,他在A州成立了自己的公司,这次他的公司生产出了一批性能很好的产品,准备宣传活动开始后的第L天到达B州进行新品拍卖,期间Bruce打算将产品拿到各个州去做 ...

  5. SAP HANA中创建层次分析视图(Hierarchy Analytic View)

    1. 创建层次Attribute View: ATTR_PRODUCT_HIERACHY ref:  http://www.cnblogs.com/omygod/archive/2013/04/30/ ...

  6. checkbox:获取所有已选中的值

    /**获取选中的checkbox值*/ function getChecked(){ var ids = ""; $("input:checkbox[name='id'] ...

  7. C语言学习 数独游戏

    摘要:花了1周多时间学习了C语言,开始练手写解数独游戏的程序. C语言学习 数独游戏 作者:乌龙哈里 时间:2015-11-22 平台:Window7 64bit,TCC 0.9.26(x86-64 ...

  8. ES6 之 Set数据结构和Map数据结构 Iterator和for...of循环

    ECMAScript 6 入门 Set数据结构 基本用法 ES6提供了新的数据结构Set.它类似于数组,但是成员的值都是唯一的,没有重复的值. Set本身是一个构造函数,用来生成Set数据结构. va ...

  9. ssh无密码登录设置方法以及出现问题 ECDSA host key 和IP地址对应的key不同的解决

    最近在做hadoop,因为要求各主机之间的用户必须相同,且为方便远程登录,需配置无密码登录 先附上ssh无密码登录设置方法: 先生成密钥并配置无ssh无密码登录本机,输入命令: ssh-keygen ...

  10. Linux的文件/目录的权限

    文件类型 权限 属主 属组 目录名/文件名drwx------ 2 alice girls 4096 9月 25 11:33 alicedrwx------ 2 rose girls 4096 9月 ...