又见面了,还是原来的配方,还是熟悉的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. 用nginx的反向代理机制解决前端跨域问题

    什么是跨域以及产生原因 跨域是指a页面想获取b页面资源,如果a.b页面的协议.域名.端口.子域名不同,或是a页面为ip地址,b页面为域名地址,所进行的访问行动都是跨域的,而浏览器为了安全问题一般都限制 ...

  2. 打开mmc后添加单元,出现停止工作的解决方法

    出现mmc停止工作,一般是其他软件的影响.关闭其他软件就可以了,但不知道是什么软件,所以只有进入干净状态.(也可以进入安全模式) 1.如何进入干净启动状态: ===================== ...

  3. 『随笔』C# 程序 修改 ConfigurationManager 后,不重启 刷新配置

    基本共识: ConfigurationManager 自带缓存,且不支持 写入. 如果 通过 文本写入方式 修改 配置文件,程序 无法刷新加载 最新配置. PS. Web.config 除外:Web. ...

  4. [BZOJ1856][SCOI2010]字符串(组合数学)

    题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1856 分析:http://www.cnblogs.com/jianglangcaiji ...

  5. Moqui学习Day1

    运行时目录以及Moqui的xml配置文件 Moqui框架部署运行主要有三个核心部分: 可执行的war包文件 运行时目录 Moqui配置文件XML格式 不管怎么使用这个可执行的war文件,你必须拥有一个 ...

  6. 修改ssh的访问端口号

    [root@redis143 ~]# vim /etc/ssh/sshd_config 修改其中的:Port 10056 重启sshd服务 同时如果有防火墙规则的话,注意修改防火墙规则,或者关闭防火墙 ...

  7. BZOJ-1050 旅行comf 并查集+乱搞

    好久以前codevs上做过的,拿着改了改.. 1050: [HAOI2006]旅行comf Time Limit: 10 Sec Memory Limit: 162 MB Submit: 2194 S ...

  8. 用WinRAR进行安装包的制作

    简单的绿色的安装包制作工具,如果不想用复杂且庞大的vs提供的制作工具,或许这个绿色解压安装包是个不错的选择. 下面我收集了一些制作的教程(百度经验的文章)和一些常用到的命令行: WinRAR自解压安装 ...

  9. Visio绘制时序图

    用visio建立时序图 1.选择模版 2.常见符号 时序图创建步骤 1.确定交互过程的上下文: 2.识别参与过程的交互对象: 3.为每个对象设置生命线: 4.从初始消息开始,依次画出随后消息: 5.考 ...

  10. excel公式处理成绩表

    一共有2个需求: 1.平均分:所有每个人的成绩/29;及格率:60分的/29;优秀率:80分/29 2.对总分进行排序,并在另一列中生成排名 平均分:=(c3+c4+.......c31)/29 及格 ...