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 ...
随机推荐
- Linux(SLES)挂载NTFS移动硬盘实践
问题描写叙述: 因为通过測试环境导出的dmp过大,但要求尽快导入至生产server,请网络室打通防火墙后发现測试网络为100M而生产网络贵为1000M却无法发挥不论什么作用即使通过networklin ...
- Linux 监控CPU 温度
安装测试系统: 硬件:普通PC机, 软件:redhat linux as 4 2.6 .9 , 安装系统自带的lm_sensors-2.8.7-2.i386 你也可以从[url]http://w ...
- Android系统移植与驱动开发——第五章--搭建开发板的测试环境
开发板上安装嵌入式系统要比手机上简洁很多,有很多扩展的接口,适合对程序进行测试,这里所提及的是S3C6410开发板.它是由三星公司推出的一款低功耗/高性价比的RISC处理器.,其中包含强大的硬件加速器 ...
- phonegap 2.8.1 toast
目录结构如下: 以上三个用红色框勾出的地方是需要修改的文件夹. 首先:添加java代码. 在src目录下新建一个包裹:org.apache.cordova 在该包裹下新建类:ToastPlugin.j ...
- (转)php 函数名称前的@有什么作用
如:$register_globals = @ini_get('register_globals'); 隐藏错误提示~如果ini_get('register_globals'); 语句错误的话`错误会 ...
- jQuery ajax - serialize() 方法
http://www.jb51.net/article/60849.htm http://www.w3school.com.cn/jquery/ajax_serialize.asp
- EBS基础—表的后缀
1._ALL或无后缀:基表,所有对数据操作最终都是对基表的操作,表包含所有不同经营单位的信息,多组织环境. 2._B/_T:也是一种基表.一些数据和验证存储在此表中. 3._TL:语言的基表,TL表支 ...
- 巧妙的Jq仿QQ游戏导航界面学习
先贴上源代码 <!doctype html> <html> <head> <meta charset="utf-8"> <ti ...
- MySQL 创建数据表
MySQL 创建数据表 创建MySQL数据表需要以下信息: 表名 表字段名 定义每个表字段 语法 以下为创建MySQL数据表的SQL通用语法: CREATE TABLE table_name (col ...
- Java并发编程之CAS
CAS(Compare and swap)比较和替换是设计并发算法时用到的一种技术.简单来说,比较和替换是使用一个期望值和一个变量的当前值进行比较,如果当前变量的值与我们期望的值相等,就使用一个新值替 ...