[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 ...
随机推荐
- bzoj 1715: [Usaco2006 Dec]Wormholes 虫洞【spfa判负环】
tag是假的,用了及其诡异的方法判负环 正权无向边和负权有向边的图 #include<iostream> #include<cstdio> #include<cstrin ...
- Akka源码分析-Cluster-Metrics
一个应用软件维护的后期一定是要做监控,akka也不例外,它提供了集群模式下的度量扩展插件. 其实如果读者读过前面的系列文章的话,应该是能够自己写一个这样的监控工具的.简单来说就是创建一个actor,它 ...
- [Qt Quick入门] 基本元素初体验
Qt Quick作为QML语言的标准库,提供了很多基本元素和控件来帮助我们构建Qt Quick应用.这节我们简要地介绍一些Qt Quick元素,如Rectangle.Item.Text.Button. ...
- H5活动的一些事
ISUX团队镇楼:https://isux.tencent.com/nine-question-of-swipe-html5-page.html IE6.7.8支持html5新元素 : http:// ...
- Python,报错NameError: name 'math' is not defined
1 #-*- coding : utf-8 -*- 2 import math 3 4 def move(x, y, step, angle=0): 5 nx = x + step * math.co ...
- CentOS 7下ElasticSearch集群搭建案例
最近在网上看到很多ElasticSearch集群的搭建方法,本人在这人使用Elasticsearch5.0.1版本,介绍如何搭建ElasticSearch集群并安装head插件和其他插件安装方法. 一 ...
- 树莓派zero_w 串口的使用(解决usb可用rxtx不可用的问题)
2018-06-0212:10:14 查了很多资料,搞了一上午,终于解决了,之前看教程做了树莓派与arduino的通信,GPIO的RXTX测试失败,无奈只能用USB,效果还可以,可是今天我想用RXTX ...
- ReLU激活函数:简单之美
出自 http://blog.csdn.net/cherrylvlei/article/details/53149381 导语 在深度神经网络中,通常使用一种叫修正线性单元(Rectified lin ...
- Masonry基础API
Masonry基础API mas_makeConstraints() 添加约束 mas_remakeConstraints() 移除之前的约束,重新添加新的约束 mas_updateConst ...
- CAD得到多行文本(com接口VB语言)
主要用到函数说明: MxDrawXCustomFunction::Mx_GetMTextContent 得到多行文本的,不包括格式控制符中的字符串值,详细说明如下: 参数 说明 LONG lId 多行 ...