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 ...
随机推荐
- 右键TXT文件-打开方式-选择默认程序提示 windows无法访问指定设备,路经或文件.您可能没有合适的权限访问这个项目
新建立一个.txt文本,把下面复制到.txt文本点保存,再把.txt文件格式修改为.reg格式, 双击导入注册表就OK了 Windows Registry Editor Version 5.00 [H ...
- OpenGIS Simple feature access
OGIS规范定义的几何对象定义 Curve:A Curve is a 1-dimensional geometric object usually stored as a sequence of Po ...
- 关于 0xCCCCCCCC
http://xingyunbaijunwei.blog.163.com/blog/static/76538067201281793111474/ http://stackoverflow.com/q ...
- iOS 修改UITextField的placeholder属性的字体颜色(修改UITextField占位符字体的颜色)
只要把原来的placeholder属性改为attributedPlaceholder属性即可 具体代码如下图:
- 12C清理asm磁盘组和文件
磁盘清理(disk scrub)可以检查逻辑坏块,并使用镜像数据自动修复数据(必须是normal.high冗余级别).磁盘清理过程和磁盘组的rebalance相结合,可以减少对I/O资源的使用.清理过 ...
- For嵌套输出图形
/*输出此图形 * * * * * * * * * ** * * * * * * * * * * * * * *解析:可以把此图形看成两部分----*---* *--* ...
- (转) Java读取文本文件中文乱码问题
http://blog.csdn.net/greenqingqingws/article/details/7395213 最近遇到一个问题,Java读取文本文件(例如csv文件.txt文件等),遇到中 ...
- srcolltop 的用法
document.body.scrollTop用法 网页可见区域宽: document.body.clientWidth;网页可见区域高: document.body.clientHeight;网页可 ...
- [转]Eclipse Java注释模板设置详解
原文链接:http://blog.csdn.net/ahhsxy/archive/2009/09/11/4542682.aspx 设置注释模板的入口: Window->Preference-&g ...
- 去掉字符串中的空格 JS JQ 正则三种不同写法
<script> function trim(str) { return str.replace(/(^\s*|\s*$)/g, "") } console.log(t ...