传送门

f[i] 表示前 i 个字符去掉多少个 的最优解

直接暴力DP

——代码

 #include <cstdio>
#include <cstring>
#include <iostream> int n, m, cnt, f[];
char s[], a[][]; inline int read()
{
int x = , f = ;
char ch = getchar();
for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -;
for(; isdigit(ch); ch = getchar()) x = (x << ) + (x << ) + ch - '';
return x * f;
} inline int min(int x, int y)
{
return x < y ? x : y;
} int main()
{
int i, j, k, l;
n = read();
m = read();
scanf("%s", s + );
for(i = ; i <= n; i++) scanf("%s", a[i] + );
for(i = ; i <= m; i++)
{
f[i] = i;
for(j = ; j <= n; j++)
{
cnt = ;
l = strlen(a[j] + );
for(k = i; k; k--)
{
if(a[j][l] == s[k]) l--;
else cnt++;
if(!l) break;
}
if(k) f[i] = min(f[i], f[k - ] + cnt);
}
}
printf("%d\n", f[m]);
return ;
}

[luoguP2875] [USACO07FEB]牛的词汇The Cow Lexicon(DP)的更多相关文章

  1. bzoj1633 / P2875 [USACO07FEB]牛的词汇The Cow Lexicon

    P2875 [USACO07FEB]牛的词汇The Cow Lexicon 三维dp 它慢,但它好写. 直接根据题意设三个状态: $f[i][j][k]$表示主串扫到第$i$个字母,匹配到第$j$个单 ...

  2. 洛谷P2875 [USACO07FEB]牛的词汇The Cow Lexicon

    P2875 [USACO07FEB]牛的词汇The Cow Lexicon 题目描述 Few know that the cows have their own dictionary with W ( ...

  3. [USACO07FEB]牛的词汇The Cow Lexicon

    https://daniu.luogu.org/problemnew/show/P2875 dp[i]表示前i-1个字符,最少删除多少个 枚举位置i, 如果打算从i开始匹配, 枚举单词j,计算从i开始 ...

  4. 【题解】Luogu P2875 [USACO07FEB]牛的词汇The Cow Lexicon

    题目描述 Few know that the cows have their own dictionary with W (1 ≤ W ≤ 600) words, each containing no ...

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

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

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

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

  7. POJ 3267-The Cow Lexicon(DP)

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

  8. The Cow Lexicon(dp)

    Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7290   Accepted: 3409 Description Few k ...

  9. USACO 2007 February Silver The Cow Lexicon /// DP oj24258

    题目大意: 输入w,l: w是接下来的字典内的单词个数,l为目标字符串长度 输入目标字符串 接下来w行,输入字典内的各个单词 输出目标字符串最少删除多少个字母就能变成只由字典内的单词组成的字符串 Sa ...

随机推荐

  1. bzoj 1679: [Usaco2005 Jan]Moo Volume 牛的呼声【枚举】

    直接枚举两两牛之间的距离即可 #include<iostream> #include<cstdio> #include<algorithm> using names ...

  2. P3222 [HNOI2012]射箭

    传送门 黄学长的代码好清楚啊--大概搞明白半平面交是个什么玩意儿了-- 设抛物线 \[y=ax^2+bx\] 则 \[y1<=ax1^2+bx1<=y2\] \[ax1^2+bx1> ...

  3. echart 参数 vue配置 图文展示

    https://blog.csdn.net/she_lover/article/details/51448967 https://blog.csdn.net/n_meng/article/detail ...

  4. [SDOI2010]外星千足虫(高斯消元)

    高斯消元裸题... 方法一:暴力,O(2^n)20分 方法二:直接Gauss,加点玄学技巧搞得好的话70分 方法三:使用bitset优化,复杂度:$O(\frac{n^3}{ω})$ 不会的同学看一下 ...

  5. 百度地图API显示多个标注点带提示的代码 / 单个标注点带提示代码

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  6. NHibernate学习笔记(3)-实体反射到数据库

    一.开发环境 NHiberate版本:4.0.4 开发工具:VS2013 数据库:SQLServer2012 二.开发流程 1.编写领域类与映射文件 namespace Domain { public ...

  7. 树莓派zero_w 串口的使用(解决usb可用rxtx不可用的问题)

    2018-06-0212:10:14 查了很多资料,搞了一上午,终于解决了,之前看教程做了树莓派与arduino的通信,GPIO的RXTX测试失败,无奈只能用USB,效果还可以,可是今天我想用RXTX ...

  8. 【转】jvm收集器

    HotSpot JVM收集器 上面有7中收集器,分为两块,上面为新生代收集器,下面是老年代收集器.如果两个收集器之间存在连线,就说明它们可以搭配使用. Serial(串行GC)收集器 Serial收集 ...

  9. Magento 多站点多域名安装教程(可以设置手机模版哟,亲 \(^o^)/)

    这篇文章是安装magento子域名的教程,请先进行安装之前,确认以下几点: 1.请先确认子域名是否已经指向你的服务器 2.可以编辑.htaccess文件 3. 熟悉Cpanel操作 我们的目标是建立一 ...

  10. 4星|《DK商业百科》:主要商业思想与事件的概括

    全书分为以下6章:1:企业的起步与发展:2:领导和人力资源:3:理财:4:战略和运营:5:营销管理:6:生产与生产后.每章有拆分为成多个比较小的专题,阐述相关专题的主要的商业思想与实践. 基本是作者按 ...