poj 3267 The Cow Lexicon 初级-》动态规划
来源:互联网 发布:财务预算软件有哪些 编辑:程序博客网 时间:2024/06/07 00:01
Description
Few know that the cows have their own dictionary withW (1 ≤ W ≤ 600) words, each containing no more 25 of the characters 'a'..'z'. Their cowmunication system, based on mooing, is not very accurate; sometimes they hear words that do not make any sense. For instance, Bessie once received a message that said "browndcodw". As it turns out, the intended message was "browncow" and the two letter "d"s were noise from other parts of the barnyard.
The cows want you to help them decipher a received message (also containing only characters in the range 'a'..'z') of lengthL (2 ≤ L ≤ 300) characters that is a bit garbled. In particular, they know that the message has some extra letters, and they want you to determine the smallest number of letters that must be removed to make the message a sequence of words from the dictionary.
Input
Line 2: L characters (followed by a newline, of course): the received message
Lines 3..W+2: The cows' dictionary, one word per line
Output
Sample Input
6 10browndcodwcowmilkwhiteblackbrownfarmer
Sample Output
2
题目:动态规划
方程:dp[i]=min(dp[i],dp[start+1]+(i-(start+1))-strlen(word[j]));
#include<iostream>#include<cstring>#include<cstdio>#include<string>#include<stack>#include<queue>#include<cmath>#include<cstdlib>using namespace std;char ls[301],word[601][100];//L串和字典串int dp[301];int main(){ int W,L,i,j,lenw,start; cin>>W>>L; cin>>ls; for(i=1;i<=W;i++) cin>>word[i]; memset(dp,0,sizeof(dp)); for(i=1;i<=L;i++) { dp[i]=dp[i-1]+1; for(j=1;j<=W;j++) { lenw=strlen(word[j]); start=i-1; for(;start>=0&&lenw>=1;) { if(ls[start--]==word[j][lenw-1]) lenw--; } if(lenw==0&&dp[i]>dp[start+1]+(i-(start+1))-strlen(word[j])) dp[i]=dp[start+1]+(i-(start+1))-strlen(word[j]); } } cout<<dp[L]<<endl; 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 DP 动态规划
- 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
- sqlserver下buffer cache
- Service——快来添加一个背景音乐播放器吧
- Hibernate事务与并发问题处理
- <iOS>网络编程(四)SOAP, WSDL, Web Service
- AIX使用vi时报History file has no read permission
- poj 3267 The Cow Lexicon 初级-》动态规划
- 第25节 类成员的访问控制
- 安装java 配置java环境 超级详细步骤有图有真相
- C/C++程序员应聘常见面试题深入剖析
- Indexes and Nulls【每日一译】--20121211
- imageNamed 与 imageWithContentsOfFile的区别
- Struts2常用标签总结
- rtsp-caching
- 控制台程序不显示控制台执行