2013年7月11日
摘要: 题目链接。分析:感叹算法的力量。方法一:设 dp[i][j] 为字符串 s, 从 i 到 j 需要添加的最少字符数。那么如果 s[i] == s[j], dp[i][j] = dp[i+1][j-1]. 如果 s[i] != s[j], dp[i][j] = min(dp[i+1][j], dp[i][j-1]) + 1.#include #include #include #include #include using namespace std;const int maxn = 5000;short dp[maxn][maxn];char s[maxn];int d(int i, int 阅读全文
posted @ 2013-07-11 19:48 Still_Raining 阅读(243) 评论(0) 推荐(0) 编辑
摘要: 题目链接。分析:和 LCS 差不多。#include #include #include #include #include using namespace std;const int maxn = 200;int G[][5] = { {5, -1, -2, -1, -3}, {-1, 5, -3, -2, -4}, {-2, -3, 5, -2, -2}, {-1, -2, -2, 5, -1}, {-3, -4, -2, -1, 0}};int dp[maxn][maxn];void trans(char *s, int n) { for(int i=... 阅读全文
posted @ 2013-07-11 18:31 Still_Raining 阅读(192) 评论(0) 推荐(0) 编辑