POJ 3267 The Cow Lexicon
来源:互联网 发布:淘宝美工双休招聘 编辑:程序博客网 时间:2024/05/18 17:00
这是个DP题,很简单。
题目大意:
给定一个字符串和N个单词,要求从字符串中去掉最少的字符后能够被这些单词表示。
直接贴代码:
#include <stdio.h>#include <string.h>const int M = 605;int len[M],dp[305],l,w;char dic[M][30],s[305];void DP(){ int i,j,k; dp[0]=1; for(i=1; i<l; i++) { dp[i]=dp[i-1]+1; for(j=0; j<w; j++) { int le=len[j]-1; k=i; if(le>k) { continue; } while(le>=0&&k>=0&&k>=le) { if(dic[j][le]==s[k]) { le--; } k--; } if(le<0) { if(dp[i]>dp[k]+i-k-len[j]) { dp[i]=dp[k]+i-k-len[j]; } } } }}int main(){ int i; while(scanf("%d%d",&w,&l)!=EOF) { scanf("%s",s); for(i=0; i<w; i++) { scanf("%s",dic[i]); len[i]=strlen(dic[i]); } DP(); printf("%d\n",dp[l-1]); } return 0;}
- poj 3267 The Cow Lexicon
- POJ 3267 The Cow Lexicon
- poj 3267 The Cow Lexicon
- POJ 3267 The Cow Lexicon
- poj 3267 The Cow Lexicon
- POJ 3267 The Cow Lexicon
- POJ 3267 The Cow Lexicon
- poj-3267-The Cow Lexicon
- POJ 3267 The Cow Lexicon
- POJ 3267 The Cow Lexicon
- POJ 3267 The Cow Lexicon
- POJ - 3267 The Cow Lexicon
- poj-3267-The Cow Lexicon
- POJ 3267 The Cow Lexicon
- POJ 3267--The Cow Lexicon
- POJ 3267 The Cow Lexicon
- 【POJ 3267】 The Cow Lexicon
- The Cow Lexicon(POJ--3267
- 简单的Eclipse连接MySQL数据库( 一)
- mysql命令语法3
- Mysql复制表结构、表数据
- tty driver总结
- 对数
- POJ 3267 The Cow Lexicon
- (转)Android: 显示UI的时候不中断正在运行的Activity(TYPE_SYSTEM_ALERT, TYPE_SYSTEM_OVERLAY)
- tar.xz 格式解压命令
- poj 题目2318 TOYS (计算几何,点与边的关系)
- 解决JLINK v8 连接到电脑后显示无法识别的USB设备
- 几种主流数据库软件的应用特点、适用范围各是什么?
- 黑马程序员_毕向东_Java基础_DAY23-24_网络编程
- Data Storage---Android数据的四种存储方式
- java annotation