Palindromic characteristics of string s with length |s| is a sequence of |s| integers, where k-th number is the total number of non-empty substrings of s which are k-palindromes.

A string is 1-palindrome if and only if it reads the same backward as forward.

A string is k-palindrome (k > 1) if and only if:

  1. Its left half equals to its right half.
  2. Its left and right halfs are non-empty (k - 1)-palindromes.

The left half of string t is its prefix of length ⌊|t| / 2⌋, and right half — the suffix of the same length. ⌊|t| / 2⌋ denotes the length of string t divided by 2, rounded down.

Note that each substring is counted as many times as it appears in the string. For example, in the string "aaa" the substring "a" appears 3 times.

Input

The first line contains the string s (1 ≤ |s| ≤ 5000) consisting of lowercase English letters.

Output

Print |s| integers — palindromic characteristics of string s.

Examples
Input
abba
Output
6 1 0 0 
Input
abacaba
Output
12 4 1 0 0 0 0 
Note

In the first example 1-palindromes are substring «a», «b», «b», «a», «bb», «abba», the substring «bb» is 2-palindrome. There are no 3- and 4-palindromes here.


  题目大意 一个k阶回文串是左右两半的串(长度为这个串的长度除以2向下取整),且这两个串都是k - 1阶回文串。统计一个串内各阶回文串的个数。

  表示这道题很简单。。然而比赛时我又把题读错。。。(我这文科渣到了某种境界)。我也不知道我怎么想的,明明看到了half,强行理解成一段。。中间那一段解释half的长度的一段,竟然成功归避。。跑去看样例猜题意了。。。绝望。。。然后不说废话了。

  根据数学的直觉和人生的哲理(瞎扯ing),可以知道,你需要用O(n^2)的时间预处理出任意一段子串是否是回文串。

  对于一个回文串是否是k阶回文串,因为它自带二分效果(因为一个回文串是对称的,所以如果它的左半边是k - 1阶回文串,那么右半边也一定是),所以可以考虑递归求解。

  据说直接求解也可以过。但是个人更喜欢把它写成记忆化搜索吧,可以省掉一个log。

  由于一个k阶回文串一定是k - 1阶回文串,所以开始就统计每个子串最高的阶数(如果不是回文串,阶数就当成0吧)的数量,最后再求个后缀和,输答案,完事。

  如果还有什么不清楚可以看代码。

Code

 /**
* Codeforces
* Problem#835D
* Accepted
* Time: 171ms
* Memory: 124500k
*/
#include <bits/stdc++.h>
using namespace std;
typedef bool boolean; int n;
char s[];
int lvls[][];
boolean vis[][];
int ans[]; inline void init() {
scanf("%s", s + );
n = strlen(s + );
} inline int getLvl(int l, int r) {
if(l == r) return ;
if(lvls[l][r] != || vis[l][r]) return lvls[l][r];
vis[l][r] = true;
int len = (r - l + ) / ;
return lvls[l][r] = (getLvl(l, l + len - ) + );
} inline void solve() {
s[] = '+', s[n + ] = '-', s[n + ] = ;
for(int i = ; i <= n; i++) {
lvls[i][i] = ;
int l = i - , r = i + ;
while(s[l] == s[r]) lvls[l][r] = , l--, r++;
l = i, r = i + ;
while(s[l] == s[r]) lvls[l][r] = , l--, r++;
}
for(int i = ; i <= n; i++)
for(int j = i; j <= n; j++) {
// int c = getLvl(i, j);
// cout << i << " " << j << " " << c << endl;
ans[getLvl(i, j)]++;
}
for(int i = n - ; i; i--)
ans[i] += ans[i + ];
for(int i = ; i <= n; i++)
printf("%d ", ans[i]);
} int main() {
init();
solve();
return ;
}

  

  

Codeforces Round #427 (Div. 2) Problem D Palindromic characteristics (Codeforces 835D) - 记忆化搜索的更多相关文章

  1. Codeforces Round #427 (Div. 2) Problem C Star sky (Codeforces 835C) - 前缀和

    The Cartesian coordinate system is set in the sky. There you can see n stars, the i-th has coordinat ...

  2. Codeforces Round #427 (Div. 2) Problem A Key races (Codeforces 835 A)

    Two boys decided to compete in text typing on the site "Key races". During the competition ...

  3. 【Codeforces Round #427 (Div. 2) D】Palindromic characteristics

    [Link]:http://codeforces.com/contest/835/problem/D [Description] 给你一个字符串; 让你在其中找到1..k阶的回文子串; 并统计它们的数 ...

  4. Codeforces Round #427 (Div. 2) Problem B The number on the board (Codeforces 835B) - 贪心

    Some natural number was written on the board. Its sum of digits was not less than k. But you were di ...

  5. Codeforces Round #425 (Div. 2) Problem C Strange Radiation (Codeforces 832C) - 二分答案 - 数论

    n people are standing on a coordinate axis in points with positive integer coordinates strictly less ...

  6. Codeforces Round #536 E. Lunar New Year and Red Envelopes /// 贪心 记忆化搜索 multiset取最大项

    题目大意: 给定n m k:(1≤n≤1e5, 0≤m≤200, 1≤k≤1e5) 表示n个时间长度内 最多被打扰m次 k个红包 接下来k行描述红包 s t d w:(1≤s≤t≤d≤n , 1≤w≤ ...

  7. CodeForces 835D - Palindromic characteristics | Codeforces Round #427 (Div. 2)

    证明在Tutorial的评论版里 /* CodeForces 835D - Palindromic characteristics [ 分析,DP ] | Codeforces Round #427 ...

  8. CodeForces 835C - Star sky | Codeforces Round #427 (Div. 2)

    s <= c是最骚的,数组在那一维开了10,第八组样例直接爆了- - /* CodeForces 835C - Star sky [ 前缀和,容斥 ] | Codeforces Round #4 ...

  9. Codeforces Round #427 (Div. 2) [ C. Star sky ] [ D. Palindromic characteristics ] [ E. The penguin's game ]

    本来准备好好打一场的,然而无奈腹痛只能带星号参加 (我才不是怕被打爆呢!) PROBLEM C - Star sky 题 OvO http://codeforces.com/contest/835/p ...

随机推荐

  1. MongoDB 在 windows 下的安装与服务配置

    本文转载地址: https://blog.csdn.net/Dorma_Bin/article/details/80851230 本地安装及网页测试 在官网下载最新的安装文件 下载地址 : https ...

  2. HTML-CSS线性渐变

    实现背景的渐变可以通过为背景添加颜色渐变的图片,也可以使用浏览器的功能来为背景添加渐变的颜色 在IE6或IE7浏览器下可以使用一下示例的CSS语句,设置filter属性来实现颜色 filter:pro ...

  3. c# 集合中有数字、字符的Orderby排序

    string[] things= new string[] { "105", "101", "102", "103", ...

  4. C# mongodb中内嵌文档数组条件查询

    样例数据: {      "_id" : "1064621564857",      "cNo" : "1064621564857 ...

  5. ip and port check 正则

    在网页开发中可能会遇到需要对在页面输入的ip和端口进行正确性验证,那么正则表达式就是最有力的工具: 1:ip的正则表达式: 格式是由“.”分割的四部分,每部分的范围是0-255: 每段的正则可以分几部 ...

  6. 使用sqoop往hdfs中导入数据供hive使用

    sqoop import -fs hdfs://x.x.x.x:8020 -jt local --connect "jdbc:oracle:thin:@x.x.x.x:1521:testdb ...

  7. 2017高教杯数学建模B 题分析

    B题原文 "拍照赚钱"是移动互联网下的一种自助式服务模式.用户下载APP,注册成为APP的会员,然后从APP上领取需要拍照的任务(比如上超市去检查某种商品的上架情况),赚取APP对 ...

  8. 【转】robot framework + python实现http接口自动化测试框架

    前言 下周即将展开一个http接口测试的需求,刚刚完成的java类接口测试工作中,由于之前犯懒,没有提前搭建好自动化回归测试框架,以至于后期rd每修改一个bug,经常导致之前没有问题的case又产生了 ...

  9. Robot Framework 教程 (3) - Resource及关键字 的使用

    From:http://www.cnblogs.com/buaawp/p/4754399.html Robot Framework 教程 (3) - Resource及关键字 的使用 在进行软件自动化 ...

  10. 【转】ETL介绍与ETL工具比较

    本文转载自:http://blog.csdn.net/u013412535/article/details/43462537 ETL,是英文 Extract-Transform-Load 的缩写,用来 ...