poj 3267 dp
来源:互联网 发布:js数组与字符串比较 编辑:程序博客网 时间:2024/05/18 00:09
题意:
问母串中至少去掉多少个字母才能是刚好由单词表中的一些单词连接而成的。
分析:
dp,f[i]表示母串从第i位起始的后缀所对应的最少去掉字母数。
f[i]有两种选择f[i + 1] + 1或者f[i + num] + num - strlen(word[j])。其中num是从第i位开始匹配word[j]所需要的母串从i位起始的后缀的前缀的长度。
#include<iostream>#include<cstdio>#include<cstring>using namespace std;const int N=300+9;int W,L;char s[N],w[N<<1][30];int f[N];int main(){ //freopen("f.txt","r",stdin); scanf("%d%d",&W,&L); scanf("%s",s); for(int i=0;i<W;i++)scanf("%s",w[i]); f[L]=0; for(int l=L-1;l>=0;l--){ f[l]=f[l+1]+1; for(int i=0;i<W;i++){ int len=strlen(w[i]); if(s[l]!=w[i][0])continue; int k=l,t=0; while(t<len&&k<L){ if(w[i][t]==s[k])t++,k++; else k++; } if(t==len)f[l]=min(f[l],f[k]+k-l-len); } } printf("%d\n",f[0]); return 0;}
0 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)
- 电项目总结
- MyCAT-1.4-RC性能测试(初步施工)
- [Android] 监听ScrollView惯性滑动事件
- log4j.properties
- Unity3D开发之Matrix4x4矩阵变换
- poj 3267 dp
- CenterOS6.5(Minimal) 搭建php
- JZOJ.1764. 游戏
- spiralMatrixII
- windows搭apache+php环境
- 函数四种调用模式以及this指向
- 1060. Are They Equal (25)
- 线程池的原理及实现
- GitHub 排名前 100 的安卓项目简介