最小回文串划分
来源:互联网 发布:mac里的照片如何导出 编辑:程序博客网 时间:2024/06/05 10:25
转移方程 dp[i] = min(dp[j-1] + 1 , dp[i]) 1<=j <=i;
#include <iostream>#include <algorithm>#include <cmath>#include <cstdio>#include <cstring>#include <cstdio>using namespace std;int dp[100000];char s[100000];int T;bool judge(int from , int to){ while(from <= to) { if(s[from] != s[to]) { return false; } from++; to--; } return true;}int main (){ cin >> T; while(T--) { cin >> s; int len = strlen(s); memset(dp,0,sizeof(dp)); for(int i = 0 ; i < len ; i++) { dp[i] = i+1; for(int j = 0 ; j <= i ; j++) { if(judge(j,i)) dp[i] = min (dp[j-1]+1,dp[i]); } } cout << dp[len-1] << endl; } return 0;}
阅读全文
0 0
- 最小回文串划分
- 回文串最小划分 dp
- 回文最小划分次数(dp之路)
- 1154 回文串划分
- 回文串划分
- 回文串划分
- 1154 回文串划分
- 回文串划分
- uva 11594 划分回文串
- 51nod1154回文串划分
- 回文串最少划分数
- UVA 11584 划分回文串
- 【51Nod1154】回文串划分
- LeetCode一道题:回文数划分的最小次数
- 动态规划 之 回文序列的最小划分
- uva11584 dp最少回文串划分
- 回文子串划分 Palindrome Partitioning
- 51nod 1154 回文串划分 (DP)
- android6.0 属性
- Android studio中NDK开发(一):CMakeLists.txt编写入门
- uva 10305 拓扑排序
- git第一次碰到冲突
- 责任链模式
- 最小回文串划分
- Ubuntu从9.10升级到14.10(64位)后编译Linux内核遇到的系列问题解决方法
- Matlab中变量的动态定义
- Unity入门操作_025_01
- 你真的会用面包屑导航吗?
- dubbo
- matlab2c使用c++实现matlab函数系列教程-sort函数
- Ubuntu下,Nginx普通安装后想要加入ssl支持model
- Android——PopupWindow