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. python中cPickle的用法

    import cPickle as p f = file('data.txt' , 'w') data = (1 , 'A' , "hello") p.dump(data , f) ...

  2. Java构造函数的继承问题

    ◎构造函数的继承 1.子类只继承父类的默认(缺省)构造函数,即无形参构造函数.如果父类没有默认构造函数,那子类不能从父类继承到任何构造函数. 3.在创建对象时,先调用父类默认构造函数对对象进行初始化, ...

  3. HDU-------(2795)Billboard(线段树区间更新)

    Billboard Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  4. hashtable 实现

    #include <stdlib.h> #include <stdio.h> #include <string.h> typedef struct _hashnod ...

  5. Android开发--Activity的创建

    1.Activity概述 Activity是android四大基本组件之一.每一个activity文件对应一个界面,一个程序由多个activity组成. 2.Android工作目录

  6. String.equals()方法的实现代码,

    通常对String的比较有两种情况,一个是使用==,另一个是使用equals()方法,注意==是对对象的地址进行比较的,而String中的equals()方法是覆盖了Object类的方法,并且实现为对 ...

  7. 解决一个报表EdmFunction报错问题

        最近测试组提了一个bug,说是某个报表点击查询报错,查看错误log,错误信息如下. 类型"Ticket.Data.SqlFuns"上指定的方法"Boolean C ...

  8. 使用Matrix控制图像或组件变换的步骤

    1.获取Matrix对象,该Matrix对象既可新创建,也可直接获取其他对象内封装的Matrix(例如Transformation对象内部) 2.调用Matrix的方法进行平移.旋转.缩放.倾斜等. ...

  9. 各种常用函数 (SQL)

    数学函数 1.绝对值 S:select abs(-1) value O:select abs(-1) value from dual   2.取整(大) S:select ceiling(-1.001 ...

  10. hdu 4618 Palindrome Sub-Array

    http://acm.hdu.edu.cn/showproblem.php?pid=4618 直接DP+记忆化 虽然时间复杂度看起来是300^4 但实际执行起来要远远小于这个值 所有可以水过 代码: ...