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 ...
随机推荐
- jQuery基础修炼圣典—DOM篇(一)
一.DOM节点的创建 1.创建节点及节点属性 通过JavaScript可以很方便的获取DOM节点,从而进行一系列的DOM操作.但实际上一般开发者都习惯性的先定义好HTML结构,但这样就非常不灵活了. ...
- javascript实例学习之六—自定义日历控件
基于之前上篇博客轻量级jquery,tool.js和base.js.自定义开发的base_datePicker插件,效果类似于jquery_ui的datePicker插件 //基于Base.js以及t ...
- javascript实例学习之四——javascript分页
话不多少,直接上代码 html代码: <!DOCTYPE html> <html lang="en"> <head> <meta char ...
- Spring Security HTTP Basic for RESTFul and FormLogin (Cookies) for web - Annotations
@Configuration @EnableWebMvcSecurity @EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabl ...
- configure: error: C++ compiler cannot create executables
今天装虚拟机LNMP环境 安装报错:configure: error: C++ compiler cannot create executables 这是因为 gcc 组件不完整,执行安装 yum i ...
- Java基础之序列化对象——反序列化对象(DeserializeObjects)
控制台程序,使用如下代码能读入包含Junk对象的文件: import java.io.*; import java.nio.file.*; class DeserializeObjects { pub ...
- linux:档案与档案系统的压缩、打包与备份
压缩比:压缩后与压缩的档案锁占用的磁碟空间大小,就称之为压缩比 压缩技术: a.将没有使用到的空间丢出去,以让档案资料占用的空间变小 b.将重复的资料统计记录(比如100个1,不是真正的用100个元位 ...
- JAX-WS(三)构建简单webservice部署到tomcat上
前言: 虽然构建本地的jax-ws的webservice很简单,但要部署到tomcat上要绕过点弯. tomcat本身和jdk都没有jaw-ws的API,所以部署的时候需要额外做点事情,有两种选择 1 ...
- 移动端下拉刷新,iScroll.js用法(转载)
本文转载自: iScroll.js 用法参考 (share)
- mysql 导出过长的数字列时变科学计数法问题解决办法
--mysql 导出数据时, 数字类型的列如果位数过长,变为科学技术发问题 concat('\t',a.IDCARD_NO) 例子: select concat('\t',a.IDCA ...