洛谷P2875 [USACO07FEB]牛的词汇The Cow Lexicon
P2875 [USACO07FEB]牛的词汇The Cow Lexicon
题目描述
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.
一个整数,表示最少去掉几个字母就可以使之变成准确的"牛语".
输入输出样例
6 10
browndcodw
cow
milk
white
black
brown
farmer
2
说明
感谢@ws_fuweidong 提供完整题面
/*
dp[i] 表示前 i 个字符去掉多少个 的最优解
*/
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n,len1,dp[];
char s[],c[][];
int main(){
scanf("%d%d%s",&n,&len1,s+);
for(int i=;i<=n;i++)scanf("%s",c[i]+);
for(int i=;i<=len1;i++){
dp[i]=i;
for(int j=;j<=n;j++){
int len2=strlen(c[j]+);
int cnt=,l=len2,k;
for(k=i;k>=;k--){
if(c[j][l]==s[k])l--;
else cnt++;
if(!l)break;
}
if(k)dp[i]=min(dp[i],dp[k-]+cnt);
}
}
printf("%d",dp[len1]);
}
洛谷P2875 [USACO07FEB]牛的词汇The Cow Lexicon的更多相关文章
- bzoj1633 / P2875 [USACO07FEB]牛的词汇The Cow Lexicon
P2875 [USACO07FEB]牛的词汇The Cow Lexicon 三维dp 它慢,但它好写. 直接根据题意设三个状态: $f[i][j][k]$表示主串扫到第$i$个字母,匹配到第$j$个单 ...
- 【题解】Luogu P2875 [USACO07FEB]牛的词汇The Cow Lexicon
题目描述 Few know that the cows have their own dictionary with W (1 ≤ W ≤ 600) words, each containing no ...
- [USACO07FEB]牛的词汇The Cow Lexicon
https://daniu.luogu.org/problemnew/show/P2875 dp[i]表示前i-1个字符,最少删除多少个 枚举位置i, 如果打算从i开始匹配, 枚举单词j,计算从i开始 ...
- [luoguP2875] [USACO07FEB]牛的词汇The Cow Lexicon(DP)
传送门 f[i] 表示前 i 个字符去掉多少个 的最优解 直接暴力DP ——代码 #include <cstdio> #include <cstring> #include & ...
- 洛谷 2953 [USACO09OPEN]牛的数字游戏Cow Digit Game
洛谷 2953 [USACO09OPEN]牛的数字游戏Cow Digit Game 题目描述 Bessie is playing a number game against Farmer John, ...
- 洛谷 P2863 [USACO06JAN]牛的舞会The Cow Prom-强连通分量(Tarjan)
本来分好组之后,就确定好了每个人要学什么,我去学数据结构啊. 因为前一段时间遇到一道题是用Lca写的,不会,就去学. 然后发现Lca分为在线算法和离线算法,在线算法有含RMQ的ST算法,前面的博客也写 ...
- 洛谷 P2863 [USACO06JAN]牛的舞会The Cow Prom
传送门 题目大意:形成一个环的牛可以跳舞,几个环连在一起是个小组,求几个小组. 题解:tarjian缩点后,求缩的点包含的原来的点数大于1的个数. 代码: #include<iostream&g ...
- 洛谷——P2863 [USACO06JAN]牛的舞会The Cow Prom
https://www.luogu.org/problem/show?pid=2863#sub 题目描述 The N (2 <= N <= 10,000) cows are so exci ...
- 洛谷P2863 [USACO06JAN]牛的舞会The Cow Prom
代码是粘的,庆幸我还能看懂. #include<iostream> #include<cstdio> #include<cmath> #include<alg ...
随机推荐
- Spring自定义配置--ConfigurationProperties
自定义配置的变量名: 在 *.properties 里面定义特定的变量 server.port=9000 amazon.associateId=habuma-20 建立Properties文件制定特定 ...
- Java for LeetCode 134 Gas Station
There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You ...
- gradle 与 gradlew
配置好gradle环境变量后(配置环境变量这里就不说了,可以自行百度),我们就可以在cmd中使用gradle命令了 在cmd中输入: gradle -v 输出如下: 这时说明gradle的环境变量配置 ...
- poj 2336 Ferry Loading II ( 【贪心】 )
Ferry Loading II Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3704 Accepted: 1884 ...
- 吴恩达机器学习笔记(八) —— 降维与主成分分析法(PCA)
主要内容: 一.降维与PCA 二.PCA算法过程 三.PCA之恢复 四.如何选取维数K 五.PCA的作用与适用场合 一.降维与PCA 1.所谓降维,就是将数据由原来的n个特征(feature)缩减为k ...
- 使用svg的几种方式
<!-- 图片,背景,框架引入svg文件 --> <img src="test.svg" alt=""> <?xml versio ...
- shell命令自动分区提示
echo ’n p 1 +20M w’ | fdisk /dev/sda
- ACM学习历程—BestCoder 2015百度之星资格赛1001 大搬家(递推 && 组合数学)
Problem Description 近期B厂组织了一次大搬家,所有人都要按照指示换到指定的座位上.指示的内容是坐在位置i 上的人要搬到位置j 上.现在B厂有N 个人,一对一到N 个位置上.搬家之后 ...
- HDU5692 Snacks
HDU5692 Snacks Problem Description 百度科技园内有n个零食机,零食机之间通过n−1条路相互连通.每个零食机都有一个值v,表示为小度熊提供零食的价值. 由于零食被频繁的 ...
- ORA-00119: invalid specification for system parameter REMOTE_LISTENER
环境说明: RAC 启动数据库报 ORA-00119: invalid specification for system parameter REMOTE_LISTENER . 检查 list ...