codeforces835D
来源:互联网 发布:加工中心编程学徒招聘 编辑:程序博客网 时间:2024/05/29 17:48
题意:
给出一个字符串,问它分别具有多少个k级字符串。
一个回文串叫做1级回文串,一个回文串为k级回文串当且仅当它的左半部分和右半部分相同,且两部分都是(k-1)级回文串。
思路:
很明显的区间dp问题, 有明显的dag关系, 然后就结束.
#include<bits/stdc++.h>using namespace std;const int maxn = 5000 + 5;int dp[maxn][maxn], num[maxn];bool ok[maxn][maxn];char s[maxn];int main(){ scanf("%s", s+1); int len = strlen(s+1); for(int i = 1; i <= len; i++) { dp[i][i] = 1; ok[i][i] = 1; } num[1] = len; for(int i = 2; i <= len; i++) { for(int j = 1; i+j-1 <= len; j++) { if(s[j] == s[i+j-1] ) { if(j+1 == i+j-1 || ok[j+1][i+j-2]) { ok[j][i+j-1] = 1; int mid = (j+i+j-1)/2; if(i&1) mid--; dp[j][i+j-1] = dp[j][mid]+1;a } } } } for(int i = 1; i <= len; i++) { for(int j = i+1; j <= len; j++) { num[dp[i][j]]++; } } for(int i = len; i >= 1; i--) { num[i]+=num[i+1]; } for(int i = 1; i <= len; i++) printf("%d ", num[i]); return 0;}
阅读全文
0 0
- codeforces835D
- Codeforces835D Palindromic characteristics
- Codeforces835D-Palindromic characteristics(DP)
- codeforces835D(94/600)
- python核心编程读书笔记--第3章 基础语句语法
- OpenCV之轮廓检测
- Google Guava学习(6)-Guava集合工具 Multiset
- 图像和流媒体 -- 详解YUV数据格式
- 用js触发CSS3-transition过渡动画
- codeforces835D
- React-Native 在iOS9之后,网络请求默认为Https请求,如需支持Http,修改info.plist文件添加键值对设置允许http访问。
- 机器学习笔记3.线性模型----教材周志华西瓜书
- 自定义JSTL标签
- 统计学习方法--K近邻法 python实现
- Redis的事务
- C语言基础
- HappyNumber leetcode算法题
- Spark的存储分析过程(一)