[luoguP2875] [USACO07FEB]牛的词汇The Cow Lexicon(DP)
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)的更多相关文章
- bzoj1633 / P2875 [USACO07FEB]牛的词汇The Cow Lexicon
P2875 [USACO07FEB]牛的词汇The Cow Lexicon 三维dp 它慢,但它好写. 直接根据题意设三个状态: $f[i][j][k]$表示主串扫到第$i$个字母,匹配到第$j$个单 ...
- 洛谷P2875 [USACO07FEB]牛的词汇The Cow Lexicon
P2875 [USACO07FEB]牛的词汇The Cow Lexicon 题目描述 Few know that the cows have their own dictionary with W ( ...
- [USACO07FEB]牛的词汇The Cow Lexicon
https://daniu.luogu.org/problemnew/show/P2875 dp[i]表示前i-1个字符,最少删除多少个 枚举位置i, 如果打算从i开始匹配, 枚举单词j,计算从i开始 ...
- 【题解】Luogu P2875 [USACO07FEB]牛的词汇The Cow Lexicon
题目描述 Few know that the cows have their own dictionary with W (1 ≤ W ≤ 600) words, each containing no ...
- POJ3267 The Cow Lexicon(DP+删词)
The Cow Lexicon Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9041 Accepted: 4293 D ...
- poj3267--The Cow Lexicon(dp:字符串组合)
The Cow Lexicon Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8211 Accepted: 3864 D ...
- POJ 3267-The Cow Lexicon(DP)
The Cow Lexicon Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8252 Accepted: 3888 D ...
- The Cow Lexicon(dp)
Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7290 Accepted: 3409 Description Few k ...
- USACO 2007 February Silver The Cow Lexicon /// DP oj24258
题目大意: 输入w,l: w是接下来的字典内的单词个数,l为目标字符串长度 输入目标字符串 接下来w行,输入字典内的各个单词 输出目标字符串最少删除多少个字母就能变成只由字典内的单词组成的字符串 Sa ...
随机推荐
- 在sql语句中使用关键字
背景 开发过程中遇到了遇到了一句sql语句一直报错,看了一下字段名和表名都对应上了,但是还是一直报错 sql语句如下: update table set using = ""hh ...
- linux Java环境变了配置
1. sudo /etc/profile 2.安装截图配置 输入javac 进行验证
- spring cxf 配置步骤
spring 项目增加web service的步骤:1.复制cxf的jar包2.web.xml配置cxf的核心控制器:org.apache.cxf.transport.servlet.CXFServl ...
- 【转】数据倾斜是多么痛?spark作业/面试/调优必备秘籍
原博文出自于: http://sanwen.net/a/gqkotbo.html 感谢! 来源:数盟 调优概述 有的时候,我们可能会遇到大数据计算中一个最棘手的问题——数据倾斜,此时Spark作业的性 ...
- centos 7 中防火墙的关闭问题
新安装的centos 7 发现有些程序端口是关闭的,想到了防火墙和selinux selinx 好关闭 /etc/sysconfig/selinux 中 追加 SELINUX=disabled 防火 ...
- javascript学习之Date对象
前几天学习了一下date对象,于是写了一个简单的时间显示放到博客页面里(位于右上角),类似这样的效果,时:分:秒 xxxx年xx月xx日. 下面来说一下具体实现步骤. 首先,既然date是一个对象,那 ...
- HTML——meta
http://www.cnblogs.com/jr1993/p/4542862.html
- jQuery 遍历 - children() 方法
jQuery 遍历参考手册 实例 找到类名为 "selected" 的所有 div 的子元素,并将其设置为蓝色: $("div").children(" ...
- iOS,Core Animation--负责视图的复合功能
简介 UIKit API UIKit是一组Objective-C API,为线条图形.Quartz图像和颜色操作提供Objective-C 封装,并提供2D绘制.图像处理及用户接口级别的动画. ...
- SpringBoot项目的mybatis逆向工程
<dependencies> <!--mybatis--> <dependency> <groupId>org.mybatis.spring.boot& ...