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

Description

Few know that the cows have their own dictionary with W (1 ≤ W ≤ 600) words, each containing no more 25 of the characters 'a'..'z'. Their cowmunication system, based on mooing, is not very accurate; sometimes they hear words that do not make any sense. For instance, Bessie once received a message that said "browndcodw". As it turns out, the intended message was "browncow" and the two letter "d"s were noise from other parts of the barnyard.

The cows want you to help them decipher a received message (also containing only characters in the range 'a'..'z') of length L (2 ≤ L ≤ 300) characters that is a bit garbled. In particular, they know that the message has some extra letters, and they want you to determine the smallest number of letters that must be removed to make the message a sequence of words from the dictionary.

Input

Line 1: Two space-separated integers, respectively: W and L 
Line 2: L characters (followed by a newline, of course): the received message 
Lines 3..W+2: The cows' dictionary, one word per line

Output

Line 1: a single integer that is the smallest number of characters that need to be removed to make the message a sequence of dictionary words.

Sample Input

6 10
browndcodw
cow
milk
white
black
brown
farmer

Sample Output

2

Source

USACO 2007 February Silver

#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int n,m;
char wen[500];
int dp[500];

struct dict
{
    char word[100];
    char theLastLaw;
    int len;
}D[800];

int main()
{
    scanf("%d%d",&n,&m);
    getchar();
    for(int i=1;i<=m;i++)
    {
        scanf("%c",&wen);
    }
    for(int i=0;i<n;i++)
    {
        scanf("%s",D.word);
        D.len=strlen(D.word);
        D.theLastLaw=D.word[D.len-1];
    }
    memset(dp,0,sizeof(dp));
    for(int i=1;i<=m;i++)
    {
        dp=dp[i-1]+1;
        for(int j=0;j<n;j++)
        {
            if(wen==D[j].theLastLaw&&i>=D[j].len)
            {
           //     cout<<i<<": "<<wen<<" catch with: "<<D[j].word<<endl;
                int flag=D[j].len-1,delet=0,pos=-1;
                for(int k=i;k>0;k--)
                {
                    if(wen[k]==D[j].word[flag])
                        flag--;
                    else
                        delet++;
                    if(flag<0){ pos=k; break;}
                }
             //   cout<<"the flag: "<<flag<<"  catch end with: "<<pos<<"  , delet is: "<<delet<<endl;
                if(flag<0)
                {
                    if(pos==-1) pos=0;
                    dp=min(dp,dp[pos-1]+delet);
                }
            }
        }
    }
    printf("%d\n",dp);
    return 0;
}

* This source code was highlighted by YcdoiT. ( style: Codeblocks )

POJ 3267 The Cow Lexicon的更多相关文章

  1. poj 3267 The Cow Lexicon (动态规划)

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

  2. poj 3267 The Cow Lexicon(dp)

    题目:http://poj.org/problem?id=3267 题意:给定一个字符串,又给n个单词,求最少删除字符串里几个字母,能匹配到n个单词里 #include <iostream> ...

  3. POJ 3267 The Cow Lexicon 简单DP

    题目链接: http://poj.org/problem?id=3267 从后往前遍历,dp[i]表示第i个字符到最后一个字符删除的字符个数. 状态转移方程为: dp[i] = dp[i+1] + 1 ...

  4. POJ - 3267 The Cow Lexicon(动态规划)

    https://vjudge.net/problem/POJ-3267 题意 给一个长度为L的字符串,以及有W个单词的词典.问最少需要从主串中删除几个字母,使其可以由词典的单词组成. 分析 状态设置很 ...

  5. PKU 3267 The Cow Lexicon(动态规划)

    题目大意:给定一个字符串和一本字典,问至少需要删除多少个字符才能匹配到字典中的单词序列.PS:是单词序列,而不是一个单词 思路:                                     ...

  6. POJ 3267:The Cow Lexicon(DP)

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

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

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

  8. POJ 3267-The Cow Lexicon(DP)

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

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

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

随机推荐

  1. 基于CoreText的基础排版引擎

    storyboard: 新建一个CTDisplayView:UIView 代码如下: #import "CTDisplayView.h" #import "CoreTex ...

  2. [C#详解] (1) 自动属性、初始化器、扩展方法

    文章来源:Slark.NET-博客园 http://www.cnblogs.com/slark/p/CSharp-focus-1.html 代码下载:点我下载 目录 前言 属性与自动属性 属性 自动属 ...

  3. HoloLens开发手记 - Unity之Spatial Sounds 空间声音

    本文主要讲述如何在项目中使用空间声音特性.我们主要讲述必须的插件组件和Unity声音组件和属性的设置来确保空间声音的实现. Enabling Spatial Sound in Unity 在Unity ...

  4. [BZOJ 1266][AHOI2006]上学路线(最短路+最小割)

    题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1266 分析: 很简单的题目,容易想到就是把所有的最短路径挑出来,然后在这个图里跑最小割 ...

  5. [POJ3177]Redundant Paths(双联通)

    在看了春晚小彩旗的E技能(旋转)后就一直在lol……额抽点时间撸一题吧…… Redundant Paths Time Limit: 1000MS   Memory Limit: 65536K Tota ...

  6. Socket网络编程--FTP客户端(1)(Windows)

    已经好久没有写过博客进行分享了.具体原因,在以后说. 这几天在了解FTP协议,准备任务是写一个FTP客户端程序.直接上干货了. 0.了解FTP作用 就是一个提供一个文件的共享协议. 1.了解FTP协议 ...

  7. Spring学习进阶(一)初识Spring

    <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://mave ...

  8. ssh开发流程

  9. 读JS高级API笔记_(DOM&&DOM2&&DOM3)哎呀——园龄才9个月啊

    ---恢复内容开始--- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http: ...

  10. JS模式:简单的图书馆享元模式

    <!DOCTYPE html> <html> <head> <title></title> </head> <body&g ...