POJ 3267 DP
来源:互联网 发布:x mirage for mac 编辑:程序博客网 时间:2024/05/16 15:26
给出一个主串,和一本字典,问最少在主串删除多少字母,可以使其匹配到字典的单词序列。
DP转移方程:
dp[i]=Min(dp[i+1]+1,dp[di]+(di-i)-len);
di: 当i 位置出现可以匹配的单词时,末端在str中的位置
#include "stdio.h"#include "string.h"#include "math.h"int Min(int a,int b){ if (a<b) return a; else return b;}int main(){ int w,l,i,j,len,di,si; char str[301]; char dic[601][26]; int dp[301]; while (scanf("%d%d",&w,&l)!=EOF) { scanf("%s",str); for (i=1;i<=w;i++) scanf("%s",dic[i]); dp[l]=0; for (i=l-1;i>=0;i--) { dp[i]=dp[i+1]+1; for (j=1;j<=w;j++) { len=strlen(dic[j]); if (len<=l-i && dic[j][0]==str[i]) { si=i; di=0; while (si<l) { if (dic[j][di]==str[si++]) di++; if (di==len) { dp[i]=Min(dp[i],dp[si]+(si-i)-len); break; } } } } } printf("%d\n",dp[0]); } return 0;}
1 0
- poj 3267(dp)
- POJ 3267 (DP)
- poj 3267 简单dp
- POJ-3267(DP)
- POJ 3267 DP
- poj 3267 dp
- poj 3267 字符串dp(倒着DP)
- poj dp
- 【dp】POJ
- 【dp】POJ
- [DP] POJ
- [DP] POJ
- [DP] POJ
- 【dp】POJ
- POJ 3267 The Cow Lexicon DP
- poj-3267-The Cow Lexicon-dp
- POJ-3267 The Cow Lexicon 简单DP
- poj 3267 The Cow Lexicon(dp)
- vs2012自动跟踪连接到改类所在的位置的设置方法
- js报TypeError $(...) is null错误,jquery失效的原因及解决办法
- C++中 const与指针的再探讨
- hadoop安装配置
- 《C Primer Plus》 学习笔记系列之(二)
- POJ 3267 DP
- Java学习之道:详解Java解析XML的四种方法
- 虚拟化(三):vsphere套件的安装注意及使用
- SGU 126 Boxes
- JacksonInFiveMinutes
- 最小路径覆盖 hdu 1151 hdu 3335
- 蟠桃记(杭电2013)
- 小白学jquery Mobile《构建跨平台APP:jQuery Mobile移动应用实战》连载五(给按钮加图标)
- HibernateTemplate、HibernateDaoSupport两种方法实现增删改查Good