POJ3267 The Cow Lexicon(DP+删词)】的更多相关文章

The Cow Lexicon Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9041   Accepted: 4293 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 c…
题目链接. 分析: 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 <cstri…
The Cow Lexicon DescriptionFew 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 word…
The Cow Lexicon Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8211   Accepted: 3864 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 c…
The Cow Lexicon Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8252   Accepted: 3888 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 c…
题目大意: 输入w,l: w是接下来的字典内的单词个数,l为目标字符串长度 输入目标字符串 接下来w行,输入字典内的各个单词 输出目标字符串最少删除多少个字母就能变成只由字典内的单词组成的字符串 Sample Input 6 10browndcodwcowmilkwhiteblackbrownfarmer Sample Output 2   当输入为 2 6 reader rad reder 输出为 1 即单词不能相互覆盖 只能各自独立组合 #include <algorithm> #incl…
Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7290   Accepted: 3409 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 sys…
http://poj.org/problem?id=3267 The Cow Lexicon Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9380   Accepted: 4469 Description Few know that the cows have their own dictionary with W (1 ≤ W ≤ 600) words, each containing no more 25 of t…
The Cow Lexicon Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8905   Accepted: 4228 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 c…
题目 1633: [Usaco2007 Feb]The Cow Lexicon 牛的词典 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 401  Solved: 216[Submit][Status] Description 没有几个人知道,奶牛有她们自己的字典,里面的有W (1 ≤ W ≤ 600)个词,每个词的长度不超过25,且由小写字母组成.她们在交流时,由于各种原因,用词总是不那么准确.比如,贝茜听到有人对她说"browndcodw"…
P2875 [USACO07FEB]牛的词汇The Cow Lexicon 题目描述 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; sometime…
又见面了,还是原来的配方,还是熟悉的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…
The Cow Lexicon Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8815 Accepted: 4162 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 cowmu…
The Cow Lexicon Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) Total Submission(s) : 16   Accepted Submission(s) : 10 Problem Description Few know that the cows have their own dictionary with W (1 ≤ W ≤ 600) words,…
P2875 [USACO07FEB]牛的词汇The Cow Lexicon 三维dp 它慢,但它好写. 直接根据题意设三个状态: $f[i][j][k]$表示主串扫到第$i$个字母,匹配到第$j$个单词的第$k$位可以留下的最多字符数 当该位不选时,就传递上一位的数据$f[i][j][k]=f[i-1][j][k]$ 当该位可以匹配时: $if(a[i]==b[j][k]\&\&f[i-1][j][k-1])$$f[i][j][k]=max(f[i][j][k],f[i-1][j][k-1…
The Cow Lexicon Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8167   Accepted: 3845 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 c…
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1633 题意: 给你一个长度为n的主串a,和一个有m个字符串s[i]的单词书(s[i].size <= 25). 问你至少删去多少个a中的字符,才能使a成为一个由s[i]组成的排列. 题解: 从后往前推. 表示状态: dp[i] = min eliminations 表示第i个及以后的字符合法时,删去字符的最小数量. 找出答案: ans = dp[0] 整个串合法. 如何转移: 对于第i个…
http://www.lydsy.com/JudgeOnline/problem.php?id=1633 一开始也想到了状态f[i]表示i以后的字符串最少删的数 然后想到的转移是 f[i]=min{f[i+1]+1, f[i+len[a]]} 但是没想到....后边其实不是完全匹配到整个单词,,而是可以删的.. 那么就转换一下,. f[i]=min{f[i+1]+1, f[i+len[a]+t]+t} t为i开始后找到单词a要删的字母个数.. 这里可以优化,当a[0]==b[i]时,才进行转移.…
继续大战dp.2018年11月30日修订,更新一下现在看到这个题目的理解(ps:就现在,poj又503了). 题意分析 这条题目的大意是这样的,问一字符串内最少删去多少的字符使其由给定的若干字符串构成.非常好的一道字符串dp题. 具体的dp解法是什么呢?考虑一下我们删去的这个过程.比如说这个式子 throw thraow 我们要不然删去a,要不然删去 “thraow”才能满足由第一个式子构成的这个条件(空串也算被第一个式子构造了).但是,程序如何知道删去a是使这俩个单词匹配的最优决策? 我们这样…
题目:http://poj.org/problem?id=3267 题意:给定一个字符串,又给n个单词,求最少删除字符串里几个字母,能匹配到n个单词里 #include <iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<stack> #include<queue> #include<iomanip> #include<cm…
题目链接: http://poj.org/problem?id=3267 从后往前遍历,dp[i]表示第i个字符到最后一个字符删除的字符个数. 状态转移方程为: dp[i] = dp[i+1] + 1;                                                 //当不能匹配时 dp[i] = std::min(dp[i], dp[msg] + (msg-i) - len[j]);  //当匹配时. 第i个字符到第msg个字符之间一共有msg-i个字符,减去…
题意  给出一个母串  和一个字典 问母串最少删去几个字母     删去后的母串是由字典里面的单词拼起来的 思路:dp[i]表示从i到母串结尾最少需要删除多少个字母  初始化dp[length]=0 最坏情况dp[i]=dp[i+1]+1 状态转移方程 dp[i]=min(dp[i],dp[p]+p-len-i) p 匹配单词的最后一个位置  len是字典里面单词的长度 i是开始匹配的位置   p-len-i的意义就是匹配过程中删除了多少个字母 参考:http://www.cnblogs.com…
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1633 [题目大意] 给出一个字符串和一个字符串集, 问要删去多少个字符该字符串才可以被字符串集完全表示 [题解] dp[i]表示长度为i时候的答案,单调dp即可 [代码] #include <cstdio> #include <algorithm> #include <cstring> using namespace std; const int N=101…
预处理出g[i][j]表示原串第i个匹配第j个单词需要去掉几个字母(匹配不上为-1) 设f[i]为i及之后满足条件要去掉的最少字母 倒着dp! f[i]初始为f[i+1]+1,转移方程为f[i]=min(f[i],f[i+strlen(b[j]+1)+g[i][j]]+g[i][j]) 也不是很难理解但是这个思路挺难想到的吧感觉-- #include<iostream> #include<cstdio> #include<cstring> using namespace…
传送门 f[i] 表示前 i 个字符去掉多少个 的最优解 直接暴力DP ——代码 #include <cstdio> #include <cstring> #include <iostream> ]; ], a[][]; inline int read() { , f = ; char ch = getchar(); ; ) + (x << ) + ch - '; return x * f; } inline int min(int x, int y) {…
Description 没有几个人知道,奶牛有她们自己的字典,里面的有W (1 ≤ W ≤ 600)个词,每个词的长度不超过25,且由小写字母组成.她们在交流时,由于各种原因,用词总是不那么准确.比如,贝茜听到有人对她说"browndcodw",确切的意思是"browncow",多出了两个"d",这两个"d"大概是身边的噪音. 奶牛们发觉辨认那些奇怪的信息很费劲,所以她们就想让你帮忙辨认一条收到的消息,即一个只包含小写字母且长…
题目描述 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…
http://poj.org/problem?id=3267 题意 : 给你一个message,是给定字符串,然后再给你字典,让你将message与字典中的单词进行匹配,输出要删掉多少字母. 思路 : 动态规划问题,不仅要找对公式,还要注意一些细节问题 样例解释 : 6是字典里有6个单词,10是给定的字符串的长度,给定的字符串可以与下面的brown和cow匹配,但要删掉两个字母 6 10 browndcodw cow milk white black brown farmer #include<…
https://daniu.luogu.org/problemnew/show/P2875 dp[i]表示前i-1个字符,最少删除多少个 枚举位置i, 如果打算从i开始匹配, 枚举单词j,计算从i开始往后,匹配完单词j的位置pos,删除的字母个数sum dp[pos]=min(dp[i]+sum) 如果不用i匹配,dp[i+1]=min(dp[i]) #include<cstdio> #include<cstring> #include<iostream> using…
Cow Exhibition Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12420   Accepted: 4964 Description "Fat and docile, big and dumb, they look so stupid, they aren't much fun..." - Cows with Guns by Dana Lyons The cows want to prove to…