题目链接

分析:

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. select菜单实现二级联动

    <tr> <th>执行人<b>*</b></th> <td> <select name="jdcld.ZXDW& ...

  2. java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.L(转)

    09-09 10:19:59.979: E/AndroidRuntime(2767): FATAL EXCEPTION: main09-09 10:19:59.979: E/AndroidRuntim ...

  3. AES对称加密算法

    package cn.jsonlu.passguard.utils; import org.apache.commons.codec.binary.Base64; import javax.crypt ...

  4. 哥的第一个Jquery程序

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs& ...

  5. 【转】那些好用的iOS开发工具

    原文:http://www.devtang.com/blog/2014/06/29/ios-dev-tools/ 前言 从苹果发明iPhone起,AppStore上的一个又一个类似flappy bir ...

  6. WBS说明

    work breakdown structure(WBS) 工作分解结构 (英语:Work Breakdown Structure, WBS)是一个详尽的,层次的(从全面到细节)的树形结构,由可交付成 ...

  7. POJ 2674 Linear world

    POJ 2674 Linear world 题目大意: 一条线上N只蚂蚁,每只蚂蚁速度固定,方向和坐标不同,碰头后掉头,求最后掉下去那只蚂蚁的时间和名字. 注意两点: 相撞可视为擦肩而过,蚂蚁们不管掉 ...

  8. linux之umask函数解析

    [lingyun@localhost umask_1]$ vim umask.c  + umask.c                                                 ...

  9. golang io需要牢记的几个点

    对于Reader比较麻烦需要记住以下: When Read encounters an error or end-of-file condition after successfully readin ...

  10. location对象,将url解析为独立片段search属性截取传递的参数

    通过location对象的search属性截取字符串传递过来的参数 search ?item=hello&name=auto&age=25 返回url中传递的参数,以?开头 funct ...