题目链接

分析:

dp[i]表示母串从第i位起始的后缀所对应的最少去掉字母数。

dp[i] = min(dp[i+res]+res-strlen(pa[j]));

其中res 为从第 i 位开始匹配 pa[j] 所需要的长度。

以下代码当做指针的练习,研究了几天C,发现C语言功底到底是提升了(虽说算法功底至今还木有)。

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring> using namespace std; const int maxn = ; char s[maxn], pa[][];
int dp[maxn]; int match(char *s1, char *s2) {
char *p1 = s1, *p2 = s2; while(*p1 && *p2) {
if((*p1++ == *p2)) p2++;
} if(*p2) return ;
else return p1-s1;
} int main() {
int W, L, i, res; char (*p)[]; scanf("%d%d", &W, &L); scanf("%s", s); for(i=, p=pa; i<W; i++) {
scanf("%s", *p++);
} dp[L] = ;
for(int i=L-; i>=; i--) {
dp[i] = dp[i+]+;
for(int j=; j<W; j++)
if((res = match(&s[i], pa[j])))
dp[i] = min(dp[i], dp[i+res]+res-(int)strlen(pa[j]));
} printf("%d\n", dp[]); return ;
}

POJ3267 The Cow Lexicon(dp)的更多相关文章

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

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

  2. POJ3267——The Cow Lexicon(动态规划)

    The Cow Lexicon DescriptionFew know that the cows have their own dictionary with W (1 ≤ W ≤ 600) wor ...

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

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

  4. POJ 3267-The Cow Lexicon(DP)

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

  5. The Cow Lexicon(dp)

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

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

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

  7. POJ 3267:The Cow Lexicon(DP)

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

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

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

  9. POJ 3267 The Cow Lexicon

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

随机推荐

  1. poj2586 Y2K Accounting Bug(贪心)

    转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://poj.org/problem?id=2586 ------ ...

  2. java 服务端解决ajax跨域问题

    //过滤器方式 可以更改为拦截器方式public class SimpleCORSFilter implements Filter { public void doFilter(ServletRequ ...

  3. [Angular 2] Template property syntax

    This lesson covers using the [input] syntax to change an element property such as “hidden” or “conte ...

  4. IOS Dictionary和Model相互转换

    // // HYBJSONModel.h // Json2ModelDemo // // Created by huangyibiao on 14-9-15. // Copyright (c) 201 ...

  5. MyISAM与InnoDB的区别

    1. 存储结构: MyISAM:(文件名以表名开始) .frm文件存储表定义 .MYD文件存储数据 .MYI文件存储索引 InnoDB: 所有的表保存在同一个(也可能多个)数据文件中,表的大小仅受限于 ...

  6. IDL实现主成分变化(PCA)

    IDL只能通过调用envi的二次接口做图像的变换,但是对于普通的数据没有提供函数.根据主成分变换的原理,用IDL写出来了,这样就不用每次再去用matlab的princomp去做了.主成分变化的基本过程 ...

  7. 【原创】贴片电容的测量方法。。。这是我从自己QQ空间转过来的,本人实操!

    电容不工作一般分为3种情况,漏电.击穿.无电容.一般检测用万用表检测阻值一般调在10K-20K为测量标准,特别是贴片电容.把万用表的笔尖点在贴片电容的两侧,如下图测量: l1.jpg l2.jpg l ...

  8. python手机号码运营商归属测试

    #手机号码测试: def number_test(): while True: number = input('Please enter your phone number:') CN_mobile ...

  9. 苹果被拒的血泪史。。。(update 2015.11)

    项目提交了N此了,也审核N次了,苹果的审核机制依旧那么不急不慢.昨天刚刚又被拒了.回忆下之前的,总结一下吧. 2015.04.28 昨天被拒非常亏,app的评级是17+,但是在app展示图里有一个比较 ...

  10. C++变量的“总分性”(Mereology)

    Stroustrup 在自传中说自己在哲学上深受 Kierkegaard (吉爾凱高爾)的影响,而讨厌黑格尔.所以看 Stroustrup 的书,很少感受到抽象理论的重要性.这也影响了C++的文化:许 ...