UVA 11584 Partitioning by Palindromes
来源:互联网 发布:linux shell jar启动 编辑:程序博客网 时间:2024/05/18 20:36
题意: 给出一串字符串,要求将它划分成尽量少的字符串,使划分后的所有子串都回文。
解法: 设dp[i]为将0~i划分后的最少回文子串数,有如下状态转移:
dp[i] = dp[j] +1,0<=j<i且区间[j+1,i]回文。
/* **********************************************Author : NeroCreated Time: 2013-8-25 15:36:08Problem id : UVA 11584Problem Name: Partitioning by Palindromes*********************************************** */#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;#define REP(i,a,b) for(int i=(a); i<(int)(b); i++)#define clr(a,b) memset(a,b,sizeof(a))const int INF = ~0u>>2;int dp[1010];char s[1010];int len;int main() { int cas; scanf("%d", &cas); while(cas--) { scanf("%s", s+1); s[0] = '@'; len = strlen(s); REP(i,0,len) dp[i] = i; REP(i,1,len) { dp[i] = min(dp[i], dp[i-1] + 1); for(int j = 1; i - j >= 1 && i + j < len && s[i-j] == s[i+j]; j ++) dp[i+j] = min(dp[i+j], dp[i-j-1] + 1); if(s[i] == s[i+1]) { dp[i+1] = min(dp[i+1], dp[i-1] + 1); for(int j = 1; i - j >= 1 && i + j + 1 < len && s[i-j] == s[i+j+1]; j ++ ) dp[i+j+1] = min(dp[i+j+1], dp[i-j-1] + 1); } } printf("%d\n", dp[len-1]); } return 0;}
- Uva 11584 - Partitioning by Palindromes
- UVa 11584 - Partitioning by Palindromes
- Uva-11584-Partitioning by Palindromes
- UVA 11584 - Partitioning by Palindromes
- UVA 11584 Partitioning by Palindromes
- UVA 11584 Partitioning by Palindromes
- UVA 11584 Partitioning by Palindromes
- UVA - 11584 Partitioning by Palindromes
- UVa:11584 Partitioning by Palindromes
- UVA 11584 Partitioning by Palindromes
- UVA 11584Partitioning by Palindromes
- UVA 11584 - Partitioning by Palindromes
- UVA 11584 Partitioning by Palindromes
- Uva 11584 Partitioning by Palindromes
- UVa 11584 Partitioning by Palindromes
- UVA - 11584 Partitioning by Palindromes
- UVA 11584 Partitioning by Palindromes
- UVA 11584 Partitioning by Palindromes
- js代码 设为首页 加入收藏
- 禁止复制,保护版权的JS
- 怎样在SQL Server 2008中配置和使用数据库备份压缩
- 压缩技术给SQL Server备份文件瘦身
- sql server 2008 中如何将一个数据库中已建好的表导入到另一个数据库中
- UVA 11584 Partitioning by Palindromes
- 常见android手机分辨率(xxhdpi,xhdpi)
- ARM及ZigBee技术实现智能家居控制器的设计
- ORACLE 用户锁定问题
- Qt中关于undefined reference to `vtable for故障总结
- What is Network Virtualization?
- xp工作组计算机无法访问的解决方法
- Socket数据传输List<E>数据
- 来自网友整理的Intent