The Cow Lexicon

Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other)
Total Submission(s) : 16   Accepted Submission(s) : 10
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
 
 
自己的方法把所有的从网上找的测试数据都过了,就是一直WA...最后没办法还是用了别人的方法,看懂了以后自己又凭自己理解敲了一遍,和原作者的代码差不多。。。。。。
 
状态转移方程dp[i]=min(dp[i+1]+1,dp[i1]+i1-i-len),dp[i]的意思是从第i个到第L个字符需要删除的最少的字符数

#include<iostream>
#include<string.h>
using namespace std;
int main()
{
int W,L,dp[301],i,j;
char word[301],dic[601][301];
cin>>W>>L>>word;
for(i=0;i<W;i++)
cin>>dic[i];
dp[L]=0;
for(i=L-1;i>=0;i--)
{
dp[i]=dp[i+1]+1;
for(j=0;j<W;j++)
{
int len=strlen(dic[j]);
if(L-i>=len&&word[i]==dic[j][0])
{
int i1=i,i2=0;
while(i1<L)
{
if(dic[j][i2]==word[i1++])
i2++;
if(i2==len)
{
dp[i]=min(dp[i],dp[i1]+i1-i-len);
break;
}
}
}
} }
cout<<dp[0]<<endl;
}

 
 

HDOJ-三部曲-1015-The Cow Lexicon的更多相关文章

  1. POJ3267 The Cow Lexicon(DP+删词)

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

  2. POJ 3267 The Cow Lexicon

    又见面了,还是原来的配方,还是熟悉的DP....直接秒了... The Cow Lexicon Time Limit: 2000MS Memory Limit: 65536K Total Submis ...

  3. POJ 3267:The Cow Lexicon(DP)

    http://poj.org/problem?id=3267 The Cow Lexicon Time Limit: 2000MS   Memory Limit: 65536K Total Submi ...

  4. The Cow Lexicon

    The Cow Lexicon Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8815 Accepted: 4162 Descr ...

  5. POJ3267——The Cow Lexicon(动态规划)

    The Cow Lexicon DescriptionFew know that the cows have their own dictionary with W (1 ≤ W ≤ 600) wor ...

  6. poj3267--The Cow Lexicon(dp:字符串组合)

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

  7. BZOJ 1633: [Usaco2007 Feb]The Cow Lexicon 牛的词典

    题目 1633: [Usaco2007 Feb]The Cow Lexicon 牛的词典 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 401  Solv ...

  8. POJ 3267-The Cow Lexicon(DP)

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

  9. bzoj1633 / P2875 [USACO07FEB]牛的词汇The Cow Lexicon

    P2875 [USACO07FEB]牛的词汇The Cow Lexicon 三维dp 它慢,但它好写. 直接根据题意设三个状态: $f[i][j][k]$表示主串扫到第$i$个字母,匹配到第$j$个单 ...

随机推荐

  1. 《javascript高级程序设计》第22章 高级技巧

    22.1 高级函数 22.1.1 安全的类型检测 22.1.2 作用域安全的构造函数 22.1.3 惰性载入函数 22.1.4 函数绑定 22.1.5 函数柯里化22.2 防篡改对象 22.2.1 不 ...

  2. iisreset和w3wp的关系

    iisreset是iis自带一个命令行工具.用法: iisreset [computername] /RESTART          停止然后重新启动所有 Internet 服务. /START   ...

  3. 在CentOS 7 MySQL / MariaDB

    在CentOS7中,MariaDB  替代了MySQL;更多复杂的疑问可以在这里查看 MariaDB versus MySQL – Compatibility Install MySQL / Mari ...

  4. 简单管理用户SESSION小记(个人观点,欢迎斧正)

    做了几年码农,记录下一般涉及到用户session管理的方法. 问题说明: a.用户如果点击退出时,可以获取用户动作,这样可以销毁session. b.用户直接关闭浏览器或者直接意外关机情况,无法获取用 ...

  5. idea tomcat +eclipse式的部署

    使用习惯了eclipse, 还没开始使用maven, 使用idea 有些不太习惯,现在记录下来,以备忘. /*这一步在tomcat使用external source时,其实是不起作用的**/   a. ...

  6. Flume数据传输事务分析[转]

    本文基于ThriftSource,MemoryChannel,HdfsSink三个组件,对Flume数据传输的事务进行分析,如果使用的是其他组件,Flume事务具体的处理方式将会不同.一般情况下,用M ...

  7. VS2005保存文件很慢

    VS2005出了点毛病,边的出奇的慢,简直不可忍受. 症状是:保存文件很慢,哪怕是修改一个变量,也要等上大概20秒 保存文件的时候,VS2005会在局域网内寻找一个主机当这个主机不在线的时候vs200 ...

  8. PostgreSQL数据库系统优点

    PostgreSQL 是世界上可以获得的最先进的开放源码的数据库系统, 它提供了多版本并行控制,支持几乎所有 SQL 构件(包括子查询,事务和用户定 义类型和函数), 并且可以获得非常广阔范围的(开发 ...

  9. Hadoop Hello World

    Hadoop单机环境配置OK后,需要找个例子测试一下Mapreduce功能.因此从Hadoop源代码中找到一个例子:WordCount.java,来验证. 编译过程如下: cd hadoop-exam ...

  10. SQL is null函数

    Sql ISNULL() 函数 使用指定的替换值替换 NULL.   语法 ISNULL ( check_expression , replacement_value )   参数 check_exp ...