zoukankan      html  css  js  c++  java
  • The Cow Lexicon(dp)

    http://poj.org/problem?id=3267

    题意:给出一个主串,一些单词,匹配这些单词,问至少要删除多少字符。

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <math.h>
     4 #include <cstring>
     5 #include <string>
     6 int dp[350];//dp[i]表示i->L删除的字符数
     7 using namespace std;
     8 int main()
     9 {
    10     int n,L;
    11     string word[606],s;
    12     cin>>n>>L;
    13     cin>>s;
    14     for (int i = 0; i < n; i ++)
    15         cin>>word[i];
    16     dp[L] = 0;
    17     for (int i = L-1; i >= 0; --i)
    18     {
    19         dp[i] = dp[i+1]+1;//单词序列在主串中不匹配的情况
    20         for (int k = 0; k < n; k ++)
    21         {
    22             int len = word[k].length();
    23             if (len <=L-i && word[k][0]==s[i])//单词长度小于等于匹配长度并且与单词的第一个字母相同
    24             {
    25                 int ps = i;//指示主串的指针
    26                 int pw = 0;//指示单词指针
    27                 while(ps < L)
    28                 {
    29                     if (word[k][pw]==s[ps])//如果匹配相同,主串指针和单词指针都移动
    30                         ++pw;
    31                     ++ps;//如果匹配不相同,只是主串指针移动
    32                     if (pw >= len)//单词匹配成功,更新
    33                     {
    34                         dp[i] = min(dp[i],dp[ps]+(ps-i)-len);//ps-i-len表示从i->ps要删除的字符数
    35                                                              //dp[ps]表示从ps->L要删除的字符数,两者相加便是
    36                                                              //从i->L要删除的字符数,这个值一定<=dp[i]
    37                     }
    38                 }
    39             }
    40 
    41         }
    42     }
    43     cout<<dp[0]<<endl;
    44     return 0;
    45 }
    View Code
  • 相关阅读:
    Sentinel-1雷达数据可以免费下载
    影像下载
    遥感影像下载地址
    ERS卫星
    alos 数据下载
    RMSE、RMS、标准差
    Landsat8数据不同波段组合的用途
    资源下载
    短视频录制的一个例子,拥有美颜滤镜、人脸贴纸功能。
    an iOS demo to demonstrate how to decorate face like faceu
  • 原文地址:https://www.cnblogs.com/lahblogs/p/3355126.html
Copyright © 2011-2022 走看看