The Cow Lexicon
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 9380   Accepted: 4469

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

  1. 6 10
  2. browndcodw
  3. cow
  4. milk
  5. white
  6. black
  7. brown
  8. farmer

Sample Output

  1. 2
  2.  
  3.   题意:给出一个串s,还有n个子串str[n],然后求s串要删除多少个字符才能让s串匹配了str[n]里的串后没有多余字符(有点表意不清,大概能懂就好)。
  1. /*
  2. dp数组的意义:从s中第i个字符开始,到尾部这段区间所删除的字符数,初始dp[len]=0;
  3. 转移方程:1) dp[i]=dp[i+1]+1 最坏情况下,每次都无法匹配
  4. 2) dp[i]=min(dp[i],dp[y]+(y-i)-l) 若有一个字符串能够匹配成功,那么
  5. 就取最优。含义:该匹配是从i到y进行匹配的,s串扫过的长度为y-i,
  6. 其中有l个字符可以匹配,因此剩下(y-i)-l个字符无法进行匹配。
  7. */
  8. #include <cstdio>
  9. #include <cstring>
  10. #include <cmath>
  11. #include <algorithm>
  12. #include <string>
  13. #include <queue>
  14. #include <iostream>
  15. using namespace std;
  16.  
  17. char s[],a[][];
  18. int dp[];
  19.  
  20. int main()
  21. {
  22. int n,len;
  23. cin>>n>>len;
  24. cin>>s;
  25. for(int i=;i<n;i++){
  26. scanf("%s",a[i]);
  27. }
  28. int j,cnt;
  29. dp[len]=;
  30. for(int i=len-;i>=;i--){
  31. dp[i]=dp[i+]+;
  32. for(j=;j<n;j++){
  33. int l=strlen(a[j]);
  34. if(l<=len-i&&a[j][]==s[i]){
  35. int x=,y=i;
  36. while(y<len){
  37. if(a[j][x]==s[y++]){
  38. x++;
  39. }
  40. if(x==l){
  41. dp[i]=min(dp[i],dp[y]+(y-i)-l);
  42. break;
  43. }
  44. }
  45. }
  46. }
  47. }
  48. cout<<dp[]<<endl;
  49. return ;
  50. }

2016-05-29

  1.  

POJ 3267:The Cow Lexicon(DP)的更多相关文章

  1. POJ 3267:The Cow Lexicon 字符串匹配dp

    The Cow Lexicon Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8905   Accepted: 4228 D ...

  2. poj 3267 The Cow Lexicon(dp)

    题目:http://poj.org/problem?id=3267 题意:给定一个字符串,又给n个单词,求最少删除字符串里几个字母,能匹配到n个单词里 #include <iostream> ...

  3. [luoguP2875] [USACO07FEB]牛的词汇The Cow Lexicon(DP)

    传送门 f[i] 表示前 i 个字符去掉多少个 的最优解 直接暴力DP ——代码 #include <cstdio> #include <cstring> #include & ...

  4. [USACO2002][poj1946]Cow Cycling(dp)

    Cow CyclingTime Limit: 1000MS Memory Limit: 30000KTotal Submissions: 2468 Accepted: 1378Description ...

  5. 【个人训练】The Cow Lexicon(POJ-3267)

    继续大战dp.2018年11月30日修订,更新一下现在看到这个题目的理解(ps:就现在,poj又503了). 题意分析 这条题目的大意是这样的,问一字符串内最少删去多少的字符使其由给定的若干字符串构成 ...

  6. 九度OJ 1153:括号匹配问题 (DP)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5193 解决:2248 题目描述: 在某个字符串(长度不超过100)中有左括号.右括号和大小写字母:规定(与常见的算数式子一样)任何一个左括 ...

  7. 51Nod 1049:最大子段和(dp)

    1049 最大子段和  基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 N个整数组成的序列a[1],a[2],a[3],-,a[n],求该序列如a[i]+ ...

  8. POJ - 3267 The Cow Lexicon(动态规划)

    https://vjudge.net/problem/POJ-3267 题意 给一个长度为L的字符串,以及有W个单词的词典.问最少需要从主串中删除几个字母,使其可以由词典的单词组成. 分析 状态设置很 ...

  9. 【POJ 3176】Cow Bowling(DP)

    题 Description The cows don't use actual bowling balls when they go bowling. They each take a number ...

随机推荐

  1. Hadoop学习笔记: HDFS

    注:该文内容部分来源于ChinaHadoop.cn上的hadoop视频教程. 一. HDFS概述 HDFS即Hadoop Distributed File System, 源于Google发表于200 ...

  2. Swagger简介

    前言 Swagger 是一款RESTFUL接口的文档在线自动生成+功能测试功能软件.本文简单介绍了在项目中集成swagger的方法和一些常见问题.如果想深入分析项目源码,了解更多内容,见参考资料. S ...

  3. 生成arff文件,csv转为arff

    一.什么是arff格式文件 1.arff是Attribute-Relation File Format缩写,从英文字面也能大概看出什么意思.它是weka数据挖掘开源程序使用的一种文件模式.由于weka ...

  4. javax.xml.ws.webserviceexception class do not have a property of the name

    我是用wsimport生成webservice 的客户端,放到工程里,调用,出现这个异常, 后来发现,是没有把package-info.java这个文件一起放到包里的缘故 解决: 连同package- ...

  5. 原来现在很多人都用SignalR来实现Chat Room

    今天从一个业余开发的群里,看到有人要求这样一个项目需求: 1,)学员可以通过在线课堂找到自己喜欢的老师和课程. 2,)每个人可以建立自己课堂,每个课堂扣分多个子房间,交流群.设置管理员:有录音功能,可 ...

  6. 理解运算符 || 和 && 及方法

    || 前面为true的话直接返回前面的值,前面为false的话返回后面的值.如下: console.log(0 || 1); console.log(1 || 0); console.log(1 || ...

  7. Swift游戏实战-跑酷熊猫 10 视差滚动背景

    原理 实现 勘误 “实现”的视频中有个错误,如下 背景移动时有个错误,看红色部分,近景归位时,第二张图片的下标是1 if arrBG[0].position.x + arrBG[0].frame.wi ...

  8. PostgreSQL Replication之第十五章 与Walbouncer 一起工作

    与Walbouncer 一起工作 在本书的最后一章,将引导您通向2014年发布的一个工具,称为walbouncer.本书中的大多数技巧说明了如何复制整个数据库实例,如何分片,等等.在最后一章,是关于w ...

  9. Maven教程(转载)

    转载自:http://www.yiibai.com/maven/ Apache Maven是一个软件项目管理和综合工具.基于项目对象模型(POM)的概念,Maven可以从一个中心资料片管理项目构建,报 ...

  10. 纪念我sgu第一个10题!

    哎,等下次再做20题纪念一下!尼玛,根本做不出来,还要到处翻别人的555555555555