UVA 10617 Again Palindrome 又是回文 dp,记忆化搜索
2013-11-09 09:31
513 查看
题意:给出一个字符串,问又几种方法能够删除字符使得字符串变成回文。
记忆化搜索即可。
递归条件写错搞了老旧。。。
代码:
记忆化搜索即可。
递归条件写错搞了老旧。。。
代码:
/* * Author: illuz <iilluzen[at]gmail.com> * Blog: http://blog.csdn.net/hcbbt * File: uva10617.cpp * Create Date: 2013-11-09 00:28:31 * Descripton: dp */ #include <cstdio> #include <cstring> #define max(a, b) (a) > (b) ? (a) : (b) const int MAXN = 65; long long dp[MAXN][MAXN]; char str[MAXN]; int t; long long solve(int beg, int end) { if (-1 != dp[beg][end]) return dp[beg][end]; if (beg >= end) return dp[beg][end] = (beg == end ? 1 : 0); else { if (str[beg] == str[end]) dp[beg][end] = max(dp[beg][end], solve(beg + 1, end) + solve(beg, end - 1) + 1); else dp[beg][end] = max(dp[beg][end], solve(beg + 1, end) + solve(beg, end - 1) - solve(beg + 1, end - 1)); return dp[beg][end]; } } int main() { scanf("%d", &t); while (t--) { memset(dp, -1, sizeof(dp)); scanf("%s", str); printf("%lld\n", solve(0, strlen(str) - 1)); } return 0; }
相关文章推荐
- UVa 10617 Again Palindrome(回文 区间dp)
- uva_10617_Again Palindrome(普通DP, 记忆化搜索)
- UVA 10617 区间DP
- UVA 10891 Game of Sum dp(记忆化搜索)
- uva 10453 Make Palindrome(dp,最小回文生成)
- UVA - 10003 Cutting Sticks(dp和记忆化搜索两种解法)
- uva 10617 Again Palindromes(DP)
- UVa 1252 - Twenty Questions(记忆化搜索,状态压缩dp)
- UVA 1630 Folding——区间DP(记忆化搜索)
- UVa 10617 Again Palindromes / 记忆化搜索
- UVa 1252 - Twenty Questions(记忆化搜索,状态压缩dp)
- UVA - 10891 Game of Sum(记忆化搜索 区间dp)
- uva10617 - Again Palindrome(dp)
- 概率DP,记忆化搜索(Expect the Expected,uva 11427)
- 记忆化搜索 区间dp uva629
- uva 10285 The Tower of Babylon(dp,记忆化搜索)
- uva 10617 回文串个数
- UVa 10651 Pebble Solitaire (DP 卵石游戏 记忆化搜索)
- uva 10617 Again Palindrome (DP)
- UVA 103 Stacking Boxes (dp + DAG上的最长路径 + 记忆化搜索)