POJ3267 The Cow Lexicon DP
来源:互联网 发布:三星s7清除电池数据 编辑:程序博客网 时间:2024/05/05 20:53
动态规划,用到字符串的处理
原字符串:s[]
字典:dic[][]
采用的从后往前的处理方式
状态转移方程:d[i]=d[i+1]+1 直接删除或匹配不成功而删除
=min(d[i],d[i+len+N]+N)
len:若s为"codw",dic[0]="cow",len=strlen(dic[0]),对于s中的每个字符s[i],每
次只检查dic中以s[i]开始的即可,
N:匹配这个串删除的字符
#include<iostream>#include<cstdio>#include<cstring>using namespace std;#define MAXX 605#define MAXY 305int min(int a,int b){ return a<b?a:b;}int main(){ int n,l,i,j,k,d[MAXY]; char dic[MAXX][MAXY],s[MAXY]; scanf("%d%d",&n,&l); scanf("%s",s); d[l]=0; for(i=0;i<n;i++) { scanf("%s",dic[i]); } for(i=l-1;i>=0;i--) { d[i]=min(MAXY,d[i+1]+1); for(j=0;j<n;j++) { if(s[i]==dic[j][0]) { int ini=i,cont=0; for(k=0;dic[j][k]&&s[ini];) { if(s[ini]==dic[j][k]) { ini++; k++; } else { cont++; ini++; } } //cout<<s[i]<<k<<endl; if(!dic[j][k]) { //cout<<i<<d[i]<<" "<<d[i+strlen(dic[j])+cont]+cont<<endl; d[i]=min(d[i],d[i+strlen(dic[j])+cont]+cont); } } } //cout<<d[i]<<" "; } cout<<d[0]<<endl;}
- POJ3267 The Cow Lexicon DP
- POJ3267 The Cow Lexicon, DP
- POJ3267 The Cow Lexicon DP
- poj3267 The Cow Lexicon -DP
- 【POJ3267】-The Cow Lexicon dp
- POJ3267 The Cow Lexicon(DP)
- poj3267 The Cow Lexicon (dp)
- POJ3267-The Cow Lexicon(dp)
- poj3267--The Cow Lexicon(dp:字符串组合)
- poj3267 The Cow Lexicon(DP)
- (POJ3267)The Cow Lexicon <DP>
- POJ3267 The Cow Lexicon
- POJ3267--The Cow Lexicon
- poj3267 The Cow Lexicon
- poj3267 The Cow Lexicon
- POJ3267-The Cow Lexicon
- POJ3267 The Cow Lexicon 题解
- POJ3267 -- The Cow Lexicon( 字符匹配dp动态规划 )
- Ubuntu服务器上SSH Server 的安装和设置
- Mat ,IplImage, CvMat 之间的转换的总结
- daima
- 程序感悟
- 黑马程序员-------JAVA图文复习一
- POJ3267 The Cow Lexicon DP
- ASP.NET MVC3中在视图中动态显示Model的DisplayName
- Linux 下安装 svn 客户端
- Android安全机制解析与应用实践
- sso单点登录,cas统一认证
- shell case
- mysql监控工具:spotlight on mysql
- 跳步游戏
- jQuery Ajax 实例 全解析