[USACO07FEB]牛的词汇The Cow Lexicon
https://daniu.luogu.org/problemnew/show/P2875
dp[i]表示前i-1个字符,最少删除多少个
枚举位置i,
如果打算从i开始匹配,
枚举单词j,计算从i开始往后,匹配完单词j的位置pos,删除的字母个数sum
dp[pos]=min(dp[i]+sum)
如果不用i匹配,dp[i+1]=min(dp[i])
#include<cstdio>
#include<cstring>
#include<iostream> using namespace std; #define N 301 int l; char s[N];
char word[][];
int len[]; int dp[N+]; void cal(int pos,int wh)
{
int sum=,tmp=dp[pos];
for(int i=;i<=len[wh];++i)
{
while(s[pos]!=word[wh][i])
{
pos++; sum++;
if(pos>l) return;
}
pos++;
}
dp[pos]=min(dp[pos],tmp+sum);
} int main()
{
int w;
scanf("%d%d",&w,&l);
scanf("%s",s+);
for(int i=;i<=w;++i)
{
scanf("%s",word[i]+);
len[i]=strlen(word[i]+);
}
int mi;
memset(dp,,sizeof(dp));
dp[]=;
for(int i=;i<=l;++i)
{
for(int j=;j<=w;++j)
if(i+len[j]-<=l)
if(s[i]==word[j][])
cal(i,j);
dp[i+]=min(dp[i]+,dp[i+]);
}
cout<<dp[l+];
}
题目描述
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.
没有几个人知道,奶牛有她们自己的字典,里面的有W (1 ≤ W ≤ 600)个词,每个词的长度不超过25,且由小写字母组成.她们在交流时,由于各种原因,用词总是不那么准确.比如,贝茜听到有人对她说"browndcodw",确切的意思是"browncow",多出了两个"d",这两个"d"大概是身边的噪音.
奶牛们发觉辨认那些奇怪的信息很费劲,所以她们就想让你帮忙辨认一条收到的消息,即一个只包含小写字母且长度为L (2 ≤ L ≤ 300)的字符串.有些时候,这个字符串里会有多余的字母,你的任务就是找出最少去掉几个字母就可以使这个字符串变成准确的"牛语"(即奶牛字典中某些词的一个排列).
输入输出格式
输入格式:
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
• 第1行:两个用空格隔开的整数,W和L.
• 第2行:一个长度为L的字符串,表示收到的信息.
• 第3行至第W+2行:奶牛的字典,每行一个词.
输出格式:
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.
一个整数,表示最少去掉几个字母就可以使之变成准确的"牛语".
输入输出样例
[USACO07FEB]牛的词汇The Cow Lexicon的更多相关文章
- bzoj1633 / P2875 [USACO07FEB]牛的词汇The Cow Lexicon
		
P2875 [USACO07FEB]牛的词汇The Cow Lexicon 三维dp 它慢,但它好写. 直接根据题意设三个状态: $f[i][j][k]$表示主串扫到第$i$个字母,匹配到第$j$个单 ...
 - 洛谷P2875 [USACO07FEB]牛的词汇The Cow Lexicon
		
P2875 [USACO07FEB]牛的词汇The Cow Lexicon 题目描述 Few know that the cows have their own dictionary with W ( ...
 - 【题解】Luogu P2875 [USACO07FEB]牛的词汇The Cow Lexicon
		
题目描述 Few know that the cows have their own dictionary with W (1 ≤ W ≤ 600) words, each containing no ...
 - [luoguP2875] [USACO07FEB]牛的词汇The Cow Lexicon(DP)
		
传送门 f[i] 表示前 i 个字符去掉多少个 的最优解 直接暴力DP ——代码 #include <cstdio> #include <cstring> #include & ...
 - BZOJ 1633: [Usaco2007 Feb]The Cow Lexicon 牛的词典
		
题目 1633: [Usaco2007 Feb]The Cow Lexicon 牛的词典 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 401 Solv ...
 - poj 3267 The Cow Lexicon (动态规划)
		
The Cow Lexicon Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8167 Accepted: 3845 D ...
 - POJ3267 The Cow Lexicon(DP+删词)
		
The Cow Lexicon Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9041 Accepted: 4293 D ...
 - POJ 3267 The Cow Lexicon
		
又见面了,还是原来的配方,还是熟悉的DP....直接秒了... The Cow Lexicon Time Limit: 2000MS Memory Limit: 65536K Total Submis ...
 - POJ 3267:The Cow Lexicon(DP)
		
http://poj.org/problem?id=3267 The Cow Lexicon Time Limit: 2000MS Memory Limit: 65536K Total Submi ...
 
随机推荐
- ubuntu安装php-curl拓展
			
首先输入apt-cache search curl | grep php查询curl的php支持名字可能会返回如下内容:php5-curl - CURL module for php5安装:sudo ...
 - just_sort
			
★实验任务 给定两个序列 a b,序列 a 原先是一个单调递增的正数序列,但是由于某些 原因,使得序列乱序了,并且一些数丢失了(用 0 表示).经过数据恢复后,找 到了正数序列 b ,且序列 a 中 ...
 - 单调队列(数列中长度不超过k的子序列和的最值)
			
★实验任务 小 F 很爱打怪,今天因为系统 bug,他提前得知了 n 只怪的出现顺序以及击 倒每只怪得到的成就值 ai.设第一只怪出现的时间为第 1 秒,这个游戏每过 1 秒 钟出现一只新怪且没被击倒 ...
 - 通用的将Excel导入数据集的方法
			
http://blog.csdn.net/baronyang/article/details/7048563
 - 虚拟机VMware中的CentOS字符界面和图形界面切换
			
在虚拟机中安装CentOS后展示的界面是图形用户界面,想切换到命令模式,于是查了linux下切换模式的方法,可是按了ctrl+alt+f1.f2....f7都是没用,后来发现是因为按键冲突的原因 问题 ...
 - POJ1149_PIGS
			
一共有n个猪圈,m个客人,一开始每个猪圈都有一定数量的猪猪.每个客人会打开一些猪圈,带走最多为某一个数量的猪猪,剩下的猪猪可以任意分配在这些开了的猪圈里面,然后重新关上.问所有的客人最多可以带走多少猪 ...
 - UVA11324_The Largest Clique
			
极大团.即求一个最大点集,使得点集中的任意两个点u,v至少存在u->v,或者v->u的路径. 是这样做的,求出所有的联通分量,然后整个图就变成了无环图,把原来若干个点缩点,点权为分量的点数 ...
 - python读取写入内存方法SringIO,BytesIO
			
python中不仅仅可以在磁盘中写入文件,还允许直接在内存中直接写入数据:需要借助StringIO和BytesIO来实现: 1.直接操作StringIO from io import StringIO ...
 - 【刷题】BZOJ 2693 jzptab
			
Description Input 一个正整数T表示数据组数 接下来T行 每行两个正整数 表示N.M Output T行 每行一个整数 表示第i组数据的结果 Sample Input 1 4 5 Sa ...
 - 单点登录(十八)----cas4.2.x客户端增加权限控制shiro
			
我们在上面章节已经完成了cas4.2.x登录启用mongodb的验证方式. 单点登录(十三)-----实战-----cas4.2.X登录启用mongodb验证方式完整流程 也完成了获取管理员身份属性 ...