UVA 11584 - Partitioning by Palindromes
来源:互联网 发布:算法编程 编辑:程序博客网 时间:2024/05/21 09:23
/*题意: 求给出串中 最少有多少个回文 dp
*/
#include<cstdio>
#include<cstring>#define INF 1<<30
char s[1010];
int d[1010];
int min(int x,int y)
{
return x>y?y:x;
}
int judge(int x,int y)
{
for(int i = x; i <= (y+x)/2; i++)
if(s[i]!=s[y-i+x])
return 0;
return 1;
}
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
scanf("%s",s);
int l = strlen(s);
for(int i = 0; i < l; i++)
d[i] = INF;
d[0] = 1;
for(int i = 1; i < l; i++)
{
for(int j = 0; j <= i; j++)
{
if(judge(j,i))
{
if(j==0)
{
d[i] = min(d[i],1);
}
else
d[i] = min(d[i],d[j-1]+1);
}
}
}
printf("%d\n",d[l-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
- 未解问题。ssh环境,两个Blob会出事。
- TableView自定义背景颜色
- hdu 2149 (博弈)
- 将java对象转换为Json
- 动态网页技术
- UVA 11584 - Partitioning by Palindromes
- .Net中 实现URL重写 支持无扩展名及任意扩展名
- 关于X-UA-Compatible 说明
- 一次OOM分析的过程
- android程序ping服务器
- 投资大师的忠告
- LeetCode - Surrounded Regions
- TH-KGC高压开关测试仪
- sizeof()于strlen()函数的区别