poj 3267 The Cow Lexicon(dp)
题目:http://poj.org/problem?id=3267
题意:给定一个字符串,又给n个单词,求最少删除字符串里几个字母,能匹配到n个单词里
#include <iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<stack>
#include<queue>
#include<iomanip>
#include<cmath>
#include<algorithm>
using namespace std; char s[][];
int min_n(int a,int b)
{
return a>b?b:a;
}
int main()
{
int n,m,i,j,d[],pm,pd,len; //d【i】表示从i到m 最少需要删多少字母
char str[];
while(cin>>n>>m)
{
cin>>str;
for(i=; i<n; i++)
cin>>s[i];
d[m] = ;
for(i=m-; i>=; i--) //从后向前
{
d[i]=d[i+]+; //先做最坏的初始化
for(j = ; j < n; j++) //从0到n挨个找
{
len = strlen(s[j]);
if(str[i]==s[j][]&&len <= (m-i))
{
pm = i;
pd=;
while(pm<m)
{
if(str[pm++]==s[j][pd]) //只加str,相同的话,s++;
pd++;
if(pd==len) //说明是子串
{
d[i]=min(d[i],d[pm]+pm-i-len); //状态转移方程
break;
}
}
}
}
}
cout<<d[]<<endl;
}
return ;
}
poj 3267 The Cow Lexicon(dp)的更多相关文章
- POJ - 3267 The Cow Lexicon(动态规划)
https://vjudge.net/problem/POJ-3267 题意 给一个长度为L的字符串,以及有W个单词的词典.问最少需要从主串中删除几个字母,使其可以由词典的单词组成. 分析 状态设置很 ...
- POJ 3267:The Cow Lexicon(DP)
http://poj.org/problem?id=3267 The Cow Lexicon Time Limit: 2000MS Memory Limit: 65536K Total Submi ...
- POJ 3267 The Cow Lexicon 简单DP
题目链接: http://poj.org/problem?id=3267 从后往前遍历,dp[i]表示第i个字符到最后一个字符删除的字符个数. 状态转移方程为: dp[i] = dp[i+1] + 1 ...
- 【POJ 3176】Cow Bowling(DP)
题 Description The cows don't use actual bowling balls when they go bowling. They each take a number ...
- [luoguP2875] [USACO07FEB]牛的词汇The Cow Lexicon(DP)
传送门 f[i] 表示前 i 个字符去掉多少个 的最优解 直接暴力DP ——代码 #include <cstdio> #include <cstring> #include & ...
- POJ 3268 Silver Cow Party (最短路径)
POJ 3268 Silver Cow Party (最短路径) Description One cow from each of N farms (1 ≤ N ≤ 1000) convenientl ...
- 【个人训练】The Cow Lexicon(POJ-3267)
继续大战dp.2018年11月30日修订,更新一下现在看到这个题目的理解(ps:就现在,poj又503了). 题意分析 这条题目的大意是这样的,问一字符串内最少删去多少的字符使其由给定的若干字符串构成 ...
- POJ 3267 The Cow Lexicon
又见面了,还是原来的配方,还是熟悉的DP....直接秒了... The Cow Lexicon Time Limit: 2000MS Memory Limit: 65536K Total Submis ...
- poj 3267 The Cow Lexicon (动态规划)
The Cow Lexicon Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8167 Accepted: 3845 D ...
随机推荐
- [ Windows] [ OS ] [ Remote Desktop ] 開啟同一個帳號同時2的連線RDP的方式
感謝同事 Allen 的Support :) 執行>gpedit.msc 電腦設定>Windows元件>遠端桌面服務>遠端桌面工作階段主機>連線>限制遠端桌面服務的 ...
- js switch表达式的例子
switch 这种表达式在很多语言中都有,比如java, C等待, 使用switch比使用if else 来得方便,来得清晰. 前言 switch 这种表达式在很多语言中都有,比如java, C等待 ...
- CodeIgniter 框架---学习笔记
1.输出sql语句:echo $this->db->last_query();
- 增加p()函数,方便开发中对变量打印调试
在开发的过程中,我们经常要输出一下变量看看得到的结果是什么,我们就要根据变量的类型选择使用echo,print_r或者var_dump,brophp框架中的p()函数会自动根据变量类型选择用什么方法为 ...
- Mindjet.MindManager“参数错误”解决办法,适用于9.0、10.0和14.0
MindManager出14.0版本了,但是在应用个别模板的时候会提示“参数错误”,然后自动关闭. 解决办法: 如果是win7系统,可以进入C:\Users\(用户名) \AppData\Loca ...
- Dapper full example
Skip to content Sign up Sign in This repository Explore Features Enterprise Blog Watch Star , Fork S ...
- 1079. Total Sales of Supply Chain (25)
时间限制 250 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A supply chain is a network of r ...
- 请给出一个左侧定宽右侧自适应的HTML结构及样式
<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content=&q ...
- wget 下载百度云jdk
oracle官网下载需要登录下载 所以从百度云下载 wget -c -O "URL"
- 1194: [HNOI2006]潘多拉的盒子 - BZOJ
Description Input 第一行是一个正整数S,表示宝盒上咒语机的个数,(1≤S≤50).文件以下分为S块,每一块描述一个咒语机,按照咒语机0,咒语机1„„咒语机S-1的顺序描述.每一块的 ...