Partitioning by Palindromes UVA
来源:互联网 发布:淘宝整点秒杀在哪 编辑:程序博客网 时间:2024/05/17 04:04
题目链接:点我
题意:
给你一个字符串,问最少能分成几个回文串.
思路:
动态规划,dp[i]表示 1 到 i 最少可以分成几个回文串,则dp[i] = min(dp[i], dp[j] + 1) && judge(j,i) : 表示由 j + 1 到 i 能形成回文串.
代码:
#include<cstring>#include<cstdio>#include<algorithm>#include<cmath>#include<queue>#include<iostream>using namespace std;const int INF = 1e9 + 10;int dp[1000+10];char ss[1000+10];bool judge(int l,int r){ while(l < r){ if(ss[l] != ss[r]) return false; l++; r--; }return true;}int main(){ int t; scanf("%d", &t); while(t--){ scanf(" %s", ss+1); int len = strlen(ss+1); for(int i = 1; i <= len; ++i){ dp[i] = INF; for(int j = 0; j < i;++j) if(judge(j+1,i)) dp[i] = min(dp[i], dp[j] + 1); }printf("%d\n",dp[len]); }return 0;}
阅读全文
0 0
- Partitioning by Palindromes UVA
- Partitioning by Palindromes UVA
- Partitioning by Palindromes UVA
- Partitioning by Palindromes UVA
- Partitioning by Palindromes UVA
- Partitioning by Palindromes UVA
- 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 11583 Partitioning by Palindromes
- UVA 11584Partitioning by Palindromes
- SourceGraph的使用
- How to compile Tensorflow with SSE4.2 and AVX instructions?
- 文章-智力与常识有什么区别?
- <note>8月11日
- 隐藏驱动的两种方法
- Partitioning by Palindromes UVA
- 小ho的01串(枚举)
- Android手势识别基础介绍
- h264 Profile_IDC Level_IDC
- 微信小程序之页面路由
- Unity手游制作记-制作通用对象管理器(三)
- dubbo 异常Please check registry access list (whitelist/blacklist)
- MAC下phpstrom使用xdebug调试
- 2017.8.10~11总结