UVa OJ 11584 - Partitioning by Palindromes
2016-09-25 13:51
295 查看
UVa OJ 11584 - Partitioning by Palindromes
Problem
Here is the: linkSolution
先对字符串进行预处理,把回文字符串的长度全部记录下来,然后用DP对回文字符串的个数进行处理。最小个数=min(之前已经处理过的长度所含回文字符串的最小值+未处理的长度所含回文字符数的最小值)#include <iostream> #include <cstdio> #include <cstring> using namespace std; const int maxn = 1005; char s[maxn]; int d[maxn], idx[maxn][maxn], cas; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); //freopen("input.txt" , "r", stdin ); //freopen("output.txt", "w", stdout); cin >> cas; while(cas--) { cin >> s+1; int n = strlen(s+1); memset(d, 0x3f, sizeof(d)); d[0] = 0; for (int i = 1; i <= n; ++i) { idx[i][i] = 1; for (int j = i+1; j <= n; ++j) { bool isOK = false; for (int k = 0; k < (j-i+1>>1); ++k) if (s[i+k] != s[j-k]) { idx[i][j] = j-i+1; isOK = true; break; } if (isOK) continue; idx[i][j] = 1; } } for (int i = 1; i <=n; ++i) { for (int j = 0; j <=i; ++j) { d[i] = min(d[i], d[j]+idx[j+1][i]); } } cout << d << '\n'; } return 0; }
相关文章推荐
- UVA 11584(p275)----Partitioning by Palindromes
- uva 11584 - Partitioning by Palindromes (dp)
- 【UVA】11584-Partitioning by Palindromes(动态规划)
- UVA11584---Partitioning by Palindromes(dp)
- 【线性结构上的动态规划】UVa 11584 - Partitioning by Palindromes
- uva 11584 Partitioning by Palindromes 线性dp
- UVA-11584 Partitioning by Palindromes 动态规划 回文串的最少个数
- UVa 11584:Partitioning by Palindromes(DP)
- UVA 11584 Partitioning by Palindromes
- UVA 11584 Partitioning by Palindromes DP
- UVa11584 - Partitioning by Palindromes(dp)
- uva 11584 Partitioning by Palindromes 回文+dp
- UVa 11584 Partitioning by Palindromes(DP 最少对称串)
- Partitioning by Palindromes UVA - 11584
- UVA 11584 一 Partitioning by Palindromes
- UVa 11584 Partitioning by Palindromes
- UVA 11584 Partitioning by Palindromes 回文串dp
- UVA 11584 Partitioning by Palindromes .
- UVa 11584 Partitioning by Palindromes(DP)
- uva 11584 Partitioning by Palindromes (动态规划)