POJ 3267:The Cow Lexicon(DP)
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 9380 | Accepted: 4469 |
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
Output
Sample Input
6 10
browndcodw
cow
milk
white
black
brown
farmer
Sample Output
2 题意:给出一个串s,还有n个子串str[n],然后求s串要删除多少个字符才能让s串匹配了str[n]里的串后没有多余字符(有点表意不清,大概能懂就好)。
/*
dp数组的意义:从s中第i个字符开始,到尾部这段区间所删除的字符数,初始dp[len]=0;
转移方程:1) dp[i]=dp[i+1]+1 最坏情况下,每次都无法匹配
2) dp[i]=min(dp[i],dp[y]+(y-i)-l) 若有一个字符串能够匹配成功,那么
就取最优。含义:该匹配是从i到y进行匹配的,s串扫过的长度为y-i,
其中有l个字符可以匹配,因此剩下(y-i)-l个字符无法进行匹配。
*/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <iostream>
using namespace std; char s[],a[][];
int dp[]; int main()
{
int n,len;
cin>>n>>len;
cin>>s;
for(int i=;i<n;i++){
scanf("%s",a[i]);
}
int j,cnt;
dp[len]=;
for(int i=len-;i>=;i--){
dp[i]=dp[i+]+;
for(j=;j<n;j++){
int l=strlen(a[j]);
if(l<=len-i&&a[j][]==s[i]){
int x=,y=i;
while(y<len){
if(a[j][x]==s[y++]){
x++;
}
if(x==l){
dp[i]=min(dp[i],dp[y]+(y-i)-l);
break;
}
}
}
}
}
cout<<dp[]<<endl;
return ;
}
2016-05-29
POJ 3267:The Cow Lexicon(DP)的更多相关文章
- POJ 3267:The Cow Lexicon 字符串匹配dp
The Cow Lexicon Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8905 Accepted: 4228 D ...
- poj 3267 The Cow Lexicon(dp)
题目:http://poj.org/problem?id=3267 题意:给定一个字符串,又给n个单词,求最少删除字符串里几个字母,能匹配到n个单词里 #include <iostream> ...
- [luoguP2875] [USACO07FEB]牛的词汇The Cow Lexicon(DP)
传送门 f[i] 表示前 i 个字符去掉多少个 的最优解 直接暴力DP ——代码 #include <cstdio> #include <cstring> #include & ...
- [USACO2002][poj1946]Cow Cycling(dp)
Cow CyclingTime Limit: 1000MS Memory Limit: 30000KTotal Submissions: 2468 Accepted: 1378Description ...
- 【个人训练】The Cow Lexicon(POJ-3267)
继续大战dp.2018年11月30日修订,更新一下现在看到这个题目的理解(ps:就现在,poj又503了). 题意分析 这条题目的大意是这样的,问一字符串内最少删去多少的字符使其由给定的若干字符串构成 ...
- 九度OJ 1153:括号匹配问题 (DP)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5193 解决:2248 题目描述: 在某个字符串(长度不超过100)中有左括号.右括号和大小写字母:规定(与常见的算数式子一样)任何一个左括 ...
- 51Nod 1049:最大子段和(dp)
1049 最大子段和 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注 N个整数组成的序列a[1],a[2],a[3],-,a[n],求该序列如a[i]+ ...
- POJ - 3267 The Cow Lexicon(动态规划)
https://vjudge.net/problem/POJ-3267 题意 给一个长度为L的字符串,以及有W个单词的词典.问最少需要从主串中删除几个字母,使其可以由词典的单词组成. 分析 状态设置很 ...
- 【POJ 3176】Cow Bowling(DP)
题 Description The cows don't use actual bowling balls when they go bowling. They each take a number ...
随机推荐
- 复制中的NOT FOR REPLICATION
错误#1 10:51 2012-9-4sp_MSget_repl_commands 重复键插入解答#1 修改distribution库下sp_MSget_repl_commands 存储过程decla ...
- matlab将多条曲线绘制在一起
figure; hold on; : plot(x(i,:),y(i,:)); end x=:*pi); hold on : y=sin(x+i*pi/)+exp(x/); plot(x,y, -(] ...
- 用仿ActionScript的语法来编写html5——第七篇,自定义按钮
第七篇,自定义按钮这次弄个简单点的,自定义按钮.其实,有了前面所定义的LSprite,LBitmap等类,定义按钮就很方便了.下面是添加按钮的代码, function gameInit(event){ ...
- UITableView + UISearchBar 实现搜索功能
#import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> @pr ...
- 11G中自动收集统计信息
在11G中,引入了一个名为 gather_stats_prog 的自动运行任务专用于自动收集统计信息.其对应的客户端名称为"auto optimizer stats collection&q ...
- C++Primer 第六章
//1.我们通过调用运算符来执行函数.调用运算符的形式是一对圆括号,他作用于一个表达式,该表达式是一个函数或者指向函数的指针.圆括号之内是用逗号分隔的实参列表,用于初始化函数形参.调用表达式的类型就是 ...
- hdu(1171)多重背包
hdu(1171) Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- How to create a project with existing folder of files in Visual Studio?
1. Select Visual Studio tool bar-> New -> Project from existing code-> continue with config ...
- List, Set, Map是否继承自Collection接口?
List, Set, Map是否继承自Collection接口? 答:List,Set是Map不是
- hdu5381 The sum of gcd
莫队算法,预处理出每个数字往后的gcd情况,每个数字的gcd只可能是他的因子,因此后面最多只可能有logn种,可以先预处理出,然后套莫队算法,复杂度O(n*sqrt(n)*log(n)). 代码 #i ...