UVA - 11584 Partitioning by Palindromes
来源:互联网 发布:一级office考试软件 编辑:程序博客网 时间:2024/05/15 23:50
题意:输入一个有小写字母组成的字符串,你的任务是将它划分成尽量少的回文串
思路:dp[i]代表到第i位的最小值,枚举它的前几位求出最小值,为了方便枚举整个长度我们 从str[1]开始输入
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int MAXN = 2000;char str[MAXN];int dp[MAXN];int check(int l,int r){ int flag = 1; for (int i = 0; i < (r-l)/2+1; i++) if (str[l+i] != str[r-i]){ flag = 0; break; } return flag;}int main(){ int t; scanf("%d",&t); while (t--){ str[0] = '0'; scanf("%s",str+1); dp[0] = 0; int len = strlen(str) - 1; for (int i = 1; i <= len; i++){ int Min = 0x3f3f3f3f,temp; for (int j = 0; j < i; j++){ if (check(j+1,i)) temp = dp[j] + 1; else temp = dp[j] + i - j; Min = min(Min,temp); } dp[i] = Min; } printf("%d\n",dp[len]); } return 0;}
1 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
- Ajax 网页和服务器通信
- [iPhone高级] 基于XMPP的IOS聊天客户端程序(XMPP服务器架构)
- cmd创建用户并初始化新用户桌面
- 八小妹揭因桃色事件自杀的女星
- IOS CoreText.framework --- 基本用法
- UVA - 11584 Partitioning by Palindromes
- DDR 了解
- 过了几天“温水”日子。
- Codeforces373B_Making Sequences is Fun_枚举长度。。。
- SNMP MIB完整手册
- 汪峰章子怡或登湖南春晚 跨年费用仅往年1/3
- FAFU 1411 质数之和
- hadoop集群job出现一个奇怪的问题
- 关于企业版 OTA发布