POJ3267 The Cow Lexicon(dp)
题目链接。
分析:
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 <cstring> using namespace std; const int maxn = ; char s[maxn], pa[][];
int dp[maxn]; int match(char *s1, char *s2) {
char *p1 = s1, *p2 = s2; while(*p1 && *p2) {
if((*p1++ == *p2)) p2++;
} if(*p2) return ;
else return p1-s1;
} int main() {
int W, L, i, res; char (*p)[]; scanf("%d%d", &W, &L); scanf("%s", s); for(i=, p=pa; i<W; i++) {
scanf("%s", *p++);
} dp[L] = ;
for(int i=L-; i>=; i--) {
dp[i] = dp[i+]+;
for(int j=; j<W; j++)
if((res = match(&s[i], pa[j])))
dp[i] = min(dp[i], dp[i+res]+res-(int)strlen(pa[j]));
} printf("%d\n", dp[]); return ;
}
POJ3267 The Cow Lexicon(dp)的更多相关文章
- POJ3267 The Cow Lexicon(DP+删词)
The Cow Lexicon Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9041 Accepted: 4293 D ...
- POJ3267——The Cow Lexicon(动态规划)
The Cow Lexicon DescriptionFew know that the cows have their own dictionary with W (1 ≤ W ≤ 600) wor ...
- poj3267--The Cow Lexicon(dp:字符串组合)
The Cow Lexicon Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8211 Accepted: 3864 D ...
- POJ 3267-The Cow Lexicon(DP)
The Cow Lexicon Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8252 Accepted: 3888 D ...
- The Cow Lexicon(dp)
Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7290 Accepted: 3409 Description Few k ...
- USACO 2007 February Silver The Cow Lexicon /// DP oj24258
题目大意: 输入w,l: w是接下来的字典内的单词个数,l为目标字符串长度 输入目标字符串 接下来w行,输入字典内的各个单词 输出目标字符串最少删除多少个字母就能变成只由字典内的单词组成的字符串 Sa ...
- 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
The Cow Lexicon Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8905 Accepted: 4228 D ...
- POJ 3267 The Cow Lexicon
又见面了,还是原来的配方,还是熟悉的DP....直接秒了... The Cow Lexicon Time Limit: 2000MS Memory Limit: 65536K Total Submis ...
随机推荐
- Directx 3D编程实例:绘制可变速旋转的三角形
最近朋友建议我写一些关于微软云技术的博客留给学校下一届的学生们看,怕下一届的MSTC断档.于是我也觉的有这个必要. 写了几篇博客之后,我觉得也有必要把这一年的学习内容放在博客做个纪念,就这样写了本篇博 ...
- Error parsing XML: not well-formed (invalid token) 报错+R文件消失解决的方法
xml报错: 这个xml文件上右键source ->format 注意:res下的文件名称不能大写 R文件消失: 在攻克了其它问题的情况下(或者其它问题还没解决先凝视掉) 手动删除gen pro ...
- [转] Are You Making a Big Mistake in This Volatile Market?
Stock market volatility continues unabated. It may be too early to tell, but I’m marking the top of ...
- static对象的高级用法
1. 函数里static对象是local的,其他如全局对象,类里的static对象都是非local的,会在程序初始化中提前创建 2. 非local的对象的创建无法确定先后次序,但能保证在main函数前 ...
- C#“简单加密文本器”的实现
本示例只能加密英文文本,使用的算法为异或算法.源代码:http://pan.baidu.com/share/link?shareid=3241348313&uk=1761850335(本示例属 ...
- Android(java)学习笔记239:多媒体之撕衣服的案例
1.撕衣服的案例逻辑: 是两者图片重叠在一起,上面我们看到的是美女穿衣服的图片,下面重叠(看不到的)是美女没有穿衣服的图片.当我们用手滑动画面,上面美女穿衣服的图片就会变成透明,这样的话下 ...
- 解决JFreeChart中文乱码问题
以下是解决X轴,Y轴中文字符乱码的代码: JFreeChart chart = ChartFactory.createBarChart3D("管网损耗",// 图表标题 " ...
- 解析JavaScript中apply和call以及bind
函数调用方法 在谈论JavaScript中apply.call和bind这三兄弟之前,我想先说下,函数的调用方式有哪些: 作为函数 作为方法 作为构造函数 通过它们的call()和apply()方法间 ...
- ASPNET5 管理应用程序的状态
1. 应用程序状态选项 在ASP.NET5当中,全局的Application对象没有了,转而被In Memory Caching所代替,ASPNET5当中有下多种管理状态的方式: HttpContex ...
- Css简介