poj 3267 The Cow Lexicon
2012-10-14 20:53
453 查看
table[i]表示以i为结尾的字符串最优解
则有 table[i] = min(table[i-1]+1, table[j] + 删除字符数) j, j+1, j+2...i删掉字符后能够和词典中的单词匹配
则有 table[i] = min(table[i-1]+1, table[j] + 删除字符数) j, j+1, j+2...i删掉字符后能够和词典中的单词匹配
#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <queue> #include <algorithm> #include <vector> #include <cstring> #include <stack> #include <cctype> #include <utility> #include <map> #include <string> #include <climits> #include <set> #include <string> #include <sstream> #include <utility> #include <ctime> //#pragma comment(linker, "/STACK:1024000000,1024000000") using std::priority_queue; using std::vector; using std::swap; using std::stack; using std::sort; using std::max; using std::min; using std::pair; using std::map; using std::string; using std::cin; using std::cout; using std::set; using std::queue; using std::string; using std::istringstream; using std::getline; using std::make_pair; using std::greater; const int INFI((INT_MAX-1) >> 1); char str[610][30]; int len[610]; char s[310]; int table[610]; int main() { int w, l; while(~scanf("%d%d", &w, &l)) { scanf("%s", s+1); for(int i = 1; i <= w; ++i) { scanf("%s", str[i]); len[i] = strlen(str[i]); } table[0] = 0; for(int i = 1; i <= l; ++i) { table[i] = INFI; for(int j = 1; j <= w; ++j) if(len[j] <= i && s[i] == str[j][len[j]-1]) { int p1 = i, p2 = len[j]-1; int count = 0; while(p1 >= 1 && p2 >= 0) if(s[p1] == str[j][p2]) { --p1; --p2; } else { --p1; ++count; } if(p2 == -1) table[i] = min(table[i], table[p1]+count); } table[i] = min(table[i], table[i-1]+1); } printf("%d\n", table[l]); } return 0; }
相关文章推荐
- POJ 3267 The Cow Lexicon
- poj 3267 The Cow Lexicon (DP)
- poj_3267 The Cow Lexicon(dp)
- 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【dp】
- poj 3267 The Cow Lexicon 动态规划
- poj3267——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 (dp)
- 【poj 3267】The Cow Lexicon 题意&题解&代码(C++)
- POJ 3267 The Cow Lexicon(DP单词匹配)
- poj 3267 The Cow Lexicon E[j]=opt{D+w(i,j)}
- POJ 3267 The Cow Lexicon DP