UVA - 11584 Partitioning by Palindromes
来源:互联网 发布:上海的美食知乎 编辑:程序博客网 时间:2024/05/24 02:38
DP:
#include<cstdio>#include<iostream>#include<algorithm>#include<cstring>using namespace std;const int maxn = 1000 + 5;char s[maxn];int d[maxn];int solve(int a, int b){ while(a<b) { if(s[a] != s[b]) return 0; ++a; --b; } return 1;}int main(){ int T; scanf("%d", &T); while(T--) { memset(s,0,sizeof(s)); memset(d,0,sizeof(s)); scanf("%s", s+1); int n = strlen(s+1); for(int i = 1; i <= n; ++i) { d[i] = d[i-1] + 1; for(int j = 1; j <= i; ++j) { if(solve(j, i)) d[i] = min(d[i], d[j-1] + 1); } } printf("%d\n", d[n]); } return 0;}
0 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
- Linux编程系统时间的获取
- poj1321
- Spark初识
- POJ 1459 && ZOJ 1734--Power Network【最大流dinic】
- HDU 2544 最短路 单源Dijkstra
- UVA - 11584 Partitioning by Palindromes
- Birt报表集成MyEclipse Web Project
- ruby的Comparable 和Enumerable
- HDU 2701 Lampyridae Teleportae
- 当超出宽度时候用省略号,鼠标移动到上面时候显示所有(不用tooltip插件)
- Swift学习记录(UITableView can not find member ...)
- android 缓存Bitmap
- HDU 2647( 拓扑+邻接表)
- 【暑期基础2】H HDU 2033 人见人爱A+B