UVA 11584(p275)----Partitioning by Palindromes
来源:互联网 发布:godaddy购买域名教程 编辑:程序博客网 时间:2024/06/11 03:09
#include<iostream>#include<cstdio>#include<algorithm>#include<string>#include<cstring>#define hellusing namespace std;const int maxn=1000+50;int n,t;string st;int d[maxn];int s[maxn][maxn];int check(int l,int r){ while(l<r) { if(st[l]!=st[r]) return 0; l++;r--; if(l>=n||r<0) break; } return 1;}void prepare(){ memset(s,0,sizeof(s)); for(int i=0;i<n;i++) for(int j=i;j<n;j++) if(check(i,j)) s[i+1][j+1]=1;}void solve(){ memset(d,0,sizeof(d)); for(int i=1; i<=n; i++) { d[i]=i; for(int j=1; j<=i; j++) { if(s[j][i]) d[i]=min(d[i],d[j-1]+1); } } printf("%d\n",d[n]);}int main(){ #ifdef hello freopen("in.in","r",stdin); #endif // hello cin>>t; for(int i=0; i<t; i++) { cin>>st; n=st.length(); prepare(); solve(); } return 0;}
0 0
- UVA 11584(p275)----Partitioning by Palindromes
- UVA 11584(p275)----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 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
- JavaWeb—DBUtils框架简介、DbUtils类、QueryRunner类 、ResultSetHandler接口
- [UVA1587]BOX
- linux下tomcat部署问题
- POJ 3414
- 3439: Kpm的MC密码 trie+主席树
- UVA 11584(p275)----Partitioning by Palindromes
- 1105. Spiral Matrix (25)
- Linux系统特点介绍集合
- csdn mysql 知识库,不错
- UVA 11882(p218)----Biggest Number
- Java web在Linux上取接口参数乱码问题
- ACL
- Java的IO流
- 数据结构算法之排序系列Java、C源码实现(3)--直接选择排序