题意  给出一个母串  和一个字典 问母串最少删去几个字母     删去后的母串是由字典里面的单词拼起来的

  思路:dp[i]表示从i到母串结尾最少需要删除多少个字母  初始化dp[length]=0 最坏情况dp[i]=dp[i+1]+1

  状态转移方程 dp[i]=min(dp[i],dp[p]+p-len-i) p 匹配单词的最后一个位置  len是字典里面单词的长度 i是开始匹配的位置   p-len-i的意义就是匹配过程中删除了多少个字母

  参考:http://www.cnblogs.com/lyy289065406/archive/2011/07/31/2122638.html

  

 #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char s[];
char dir[][];
int dp[];
int main(){
int w,l;
scanf("%d%d",&w,&l);
scanf("%s",s);
for(int i=;i<w;i++){
scanf("%s",dir[i]);
}
dp[l]=;
for(int i=l-;i>=;i--){
dp[i]=dp[i+]+;
for(int j=;j<w;j++){
int len=strlen(dir[j]);
int pm=;
if(l-i+>=len&&s[i]==dir[j][]){
int p2=i;
while(p2<l){
if(dir[j][pm]==s[p2++]){
pm++;
}
if(pm==len){
dp[i]=min(dp[i],dp[p2]+p2-i-len);
break;
}
}
}
}
}
cout<<dp[]<<endl;
return ;
}

The Cow Lexicon POJ - 3267 dp的更多相关文章

  1. POJ 3267:The Cow Lexicon 字符串匹配dp

    The Cow Lexicon Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8905   Accepted: 4228 D ...

  2. POJ 3267:The Cow Lexicon(DP)

    http://poj.org/problem?id=3267 The Cow Lexicon Time Limit: 2000MS   Memory Limit: 65536K Total Submi ...

  3. POJ 3267 The Cow Lexicon

    又见面了,还是原来的配方,还是熟悉的DP....直接秒了... The Cow Lexicon Time Limit: 2000MS Memory Limit: 65536K Total Submis ...

  4. POJ 3267-The Cow Lexicon(DP)

    The Cow Lexicon Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8252   Accepted: 3888 D ...

  5. poj 3267 The Cow Lexicon (动态规划)

    The Cow Lexicon Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8167   Accepted: 3845 D ...

  6. POJ3267 The Cow Lexicon(DP+删词)

    The Cow Lexicon Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9041   Accepted: 4293 D ...

  7. poj3267--The Cow Lexicon(dp:字符串组合)

    The Cow Lexicon Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8211   Accepted: 3864 D ...

  8. POJ 3267为什么优先队列超时,DP就能过,难过

    The Cow Lexicon Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11846 Accepted: 5693 Desc ...

  9. The Cow Lexicon

    The Cow Lexicon Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8815 Accepted: 4162 Descr ...

随机推荐

  1. (5)学习笔记 ) ASP.NET CORE微服务 Micro-Service ---- 熔断降级(Polly)

    一. 什么是熔断降级 熔断就是“保险丝”.当出现某些状况时,切断服务,从而防止应用程序不断地尝试执行可能会失败的操作给系统造成“雪崩”,或者大量的超时等待导致系统卡死. 降级的目的是当某个服务提供者发 ...

  2. 【NLP】Attention Model(注意力模型)学习总结

    最近一直在研究深度语义匹配算法,搭建了个模型,跑起来效果并不是很理想,在分析原因的过程中,发现注意力模型在解决这个问题上还是很有帮助的,所以花了两天研究了一下. 此文大部分参考深度学习中的注意力机制( ...

  3. Tomcat搭建Web 应用服务器

    和安卓联合开发,测试手机设配效果,被安卓开发大神同事一顿鄙视之后,愤然而起自己搭建了一个本地服务器(愤怒 玻璃心使我成长~哈哈) java+tomcat安装 java安装 注册oracle账号: 手机 ...

  4. poj3984 广度搜索BFS

      迷宫问题 Description 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1 ...

  5. pip3 升级失败的解决方法!亲测有效

    pip3 --default-timeout=10000 install -U pip 注意:由于防火长城的存在,会导致更新失败,如果你加上--default-timeout=10000  这个就ok ...

  6. net core 小坑杂记之配置文件读取 02 (控制器里读)

    上次更新博客的时候提到了如何在EF的上下文里读取配置,这次介绍一下在控制器里如何读取. 先说一种简单易懂的: 首先以键值对的形式在appsettings里添加一条配置信息,接着Startup里注入配置 ...

  7. Django lazy load 懒加载 倒序查询

    Django orm默认懒加载   Django orm默认使用的懒加载,即使用的时候才去访问数据库,且每次默认取最少的数据,当然这样有好处也有坏处... 坏处: 会导致频繁的查询数据库,如涉及到外键 ...

  8. elasticsearch5.0版本的head安装

    elasticsearch5.0版本的head安装 elasticsearch5.0版本由于刚出不久,并且与2.0版本的差距较大.所以,目前大家对5.0的一些使用还有所陌生.这里先把关于head插件的 ...

  9. 1244. Minimum Genetic Mutation

    描述 A gene string can be represented by an 8-character long string, with choices from "A", ...

  10. Java案例-用户注册邮箱绑定激活功能实现

    <–start–> 需求描述:当客户打开收到邮箱激活码的邮件,点击激活链接,正确填写激活码后就会完成邮箱激活的步骤. 在后台编程代码编写中,有以下几个要点: ① 接收客户的手机号码和邮箱激 ...