HDOJ-三部曲-1015-The Cow Lexicon

时间:2022-12-31 08:07:35

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&lpar;DP&plus;删词&rpar;

    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&lpar;动态规划&rpar;

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

  6. poj3267--The Cow Lexicon&lpar;dp&colon;字符串组合&rpar;

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

  7. BZOJ 1633&colon; &lbrack;Usaco2007 Feb&rsqb;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&lpar;DP&rpar;

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

  9. bzoj1633 &sol; P2875 &lbrack;USACO07FEB&rsqb;牛的词汇The Cow Lexicon

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

随机推荐

  1. cocoaPods 的使用

    打开 终端 1. 移除系统自带的 因为该rub已经被和谐了 使用ruby.taobao.org MCJ:~ MCJ$ sudo gem sources -l *** CURRENT SOURCES * ...

  2. HTMlhleper

    @{ ViewBag.Title = "Index";} <h2>Index</h2> <div> @{ int id=12121; var I ...

  3. 第三篇——软件之殇,WE ARE THOUSANDS APART&excl;

    软件工程是一门工程性的学科,其目标主要是成功地建造一个大型软件系统.这其中包括:付出较低的开发成本:达到要求的软件功能:取得较好的软件性能:开发的软件易于移植:需要较低的维护费用:能按时完成开发任务, ...

  4. WinForm程序用使用List对象绑定DataGridView数据源

    1. 在用List<T>对象绑定DataGridView数据源属性的时候,数据源的内容不会动态更新,如果List<T>对象集合中的数据发生变化,那么数据控件的数据源是不会得到更 ...

  5. python 操作 excel

    python操作execel主要是读写 读 通过 http://pypi.python.org/pypi/xlrd 写 通过 http://pypi.python.org/pypi/xlwd 下载ta ...

  6. ASP&period;NET 学习的总结

    应用程序域 使用.Net建立的可执行程序*.exe,并没有直接承载到进程当中,而是承载到应用程序域(AppDomain)当中.应用程序域是.Net引入的一个新概念,它比进程所占用的资源要少,可以被看做 ...

  7. VI 命令学习指南

    ctrl+b 屏幕向后(上)移动一屏 ctrl+f 屏幕向前(下)移动一屏 ctrl+u 屏幕向后(上)移动半屏 ctrl+d 屏幕向前(下)移动半屏

  8. &lbrack;BZOJ 2165&rsqb; 大楼 【DP &plus; 倍增 &plus; 二进制】

    题目链接:BZOJ - 2165 题目分析: 这道题我读了题之后就想不出来怎么做,题解也找不到,于是就请教了黄学长,黄学长立刻秒掉了这道题,然后我再看他的题解才写出来..Orz 使用 DP + 倍增 ...

  9. Android主页Activity对多个Fragment实现不同的沉浸式标题(图片或者文字标题)

    提示:讲解的该例实现是 FragmentTabHost + Fragment 实现: 1.示例效果图: 2.场景需求: 如示例图所示,在首页实现轮播图的沉浸,而 “发现” 和“我的”页是标题的沉浸. ...

  10. 《DSP using MATLAB》Problem 5&period;37

    证明过程: 代码: %% +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...