time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

回文串

递归解法

#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
typedef long long LL;
#define MAXN 5050
#define N 100
/*
1阶回文串就是左右两边读相等
k 回文串就是从中间分开 左右两边都是k-1阶回文串
预处理a[i][j]确定i 到j 是不是回文串
然后递归 找每个固定阶的子串 k阶串肯定是k+1阶串!
*/
int g[MAXN][MAXN], ans[MAXN];
char str[MAXN];
int solve(int l, int r)
{
if (!g[l][r]) return ;//不回文
if (l == r) return ;
if (l + == r) return ;
if ((l - r + ) % == )
return solve(l, (l + r) / ) + ;
else
return solve(l, (l + r) / - ) + ;
}
int main()
{
scanf("%s", str + );
int len = strlen(str+); for (int i = ; i <= len; i++)
{
g[i][i] = ;
if (i + <= len&&str[i] == str[i + ])
g[i][i + ] = ;
} for (int k = ; k <= len; k++)
{
for (int i = ; i <= len; i++)
{
int r = i + k - ;
if (r > len) break;
if (g[i + ][r - ] && str[r] == str[i])
g[i][r] = ;
}
} for (int i = ; i <= len; i++)
{
for (int j = ; j <= len; j++)
ans[solve(i, j)]++;//solve(i,j)b表示从i到j的连续子串是一个几阶回文串
} for (int i = len - ; i >= ; i--)
ans[i] += ans[i + ]; for (int i = ; i <= len; i++)
printf("%d ", ans[i]);
return ;
}

最新文章

  1. 如何查看经过编码的cookie?
  2. 模板插件aTpl.js新增功能
  3. imx6 MFG TOOL 分析
  4. php执行的困惑
  5. 高性能MySql进化论(十一):常见查询语句的优化
  6. RSA算法原理(二)
  7. POJ3690 Constellations 【KMP】
  8. hdu Eddy&#39;s picture (最小生成树)
  9. Android -- 从源码的角度一步步打造自己的TextView
  10. ReactNative Android之原生UI组件动态addView不显示问题解决
  11. JQuery之事件处理
  12. 【最短路+最大流】上学路线@安徽OI2006
  13. css边框的一些属性
  14. MySql Undo Redo
  15. python解决json序列化时间格式
  16. 初识Quartz (一)
  17. es6(15)--generator
  18. Code Chef December Challenge 2018题解
  19. myeclipse设置jvm参数的三种方式
  20. bzoj1294 [SCOI2009]围豆豆

热门文章

  1. CSS实现居中的方式
  2. [IOI1998]Polygon
  3. python获取主机名和用户名
  4. 388 Longest Absolute File Path 最长的绝对文件路径
  5. jQuery实现文字横向滚动效果
  6. Android中出现Error:In (declare-styleable) FontFamilyFont, unable to find attribute android:font
  7. Android 滚动RecyclerView加载图片时的流畅度优化
  8. git Eclipse项目不显示当前分支
  9. Mantis 配置与使用学习
  10. SQL 语句在存储过程执行和在SSMS中执行的差异