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 ;
}

D. Palindromic characteristics的更多相关文章

  1. Palindromic characteristics CodeForces - 835D (区间DP,预处理回文串问题)

    Palindromic characteristics of string s with length |s| is a sequence of |s|integers, where k-th num ...

  2. Codeforces Round #427 (Div. 2) Problem D Palindromic characteristics (Codeforces 835D) - 记忆化搜索

    Palindromic characteristics of string s with length |s| is a sequence of |s| integers, where k-th nu ...

  3. 【CF835D】Palindromic characteristics 加强版 解题报告

    [CF835D]Palindromic characteristics 加强版 Description 给你一个串,让你求出\(k\)阶回文子串有多少个.\(k\)从\(1\)到\(n\). \(k\ ...

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

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

  5. 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 ...

  6. D. Palindromic characteristics 解析(DP)

    Codeforce 835 D. Palindromic characteristics 解析(DP) 今天我們來看看CF835D 題目連結 題目 略,請看原題 前言 想不到這種狀態... @copy ...

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

    本题是个简单的区间dp 最近都没时间做题了,被我妈强制喊回去,然后颓废了10天(回家也没发控制住自己= = 我的锅),计划都打乱了,本来还报名了百度之星,然后没时间参加 #include<cma ...

  8. 【XSY2534】【CF835D】Palindromic characteristics 回文自动机

    题目大意 ​ 一个字符串\(s\)是\(1\)−回文串当且仅当这个串是回文串. ​ 一个串\(s\)是\(k\)−回文串\((k>1)\)当且仅当\(s\)的前一半与后一半相同且\(s\)的前一 ...

  9. 【CodeForces】835D Palindromic characteristics

    [题意]给你一个串,让你求出k阶回文子串有多少个.k从1到n.k阶子串的定义是:子串本身是回文串,而且它的左半部分也是回文串. [算法]区间DP [题解]涉及回文问题的区间DP都可以用类似的写法,就是 ...

随机推荐

  1. 377 Combination Sum IV 组合之和 IV

    Given an integer array with all positive numbers and no duplicates, find the number of possible comb ...

  2. 374 Guess Number Higher or Lower 猜数字大小

    我们正在玩一个猜数字游戏. 游戏规则如下:我从 1 到 n 选择一个数字. 你需要猜我选择了哪个数字.每次你猜错了,我会告诉你这个数字是大了还是小了.你调用一个预先定义好的接口 guess(int n ...

  3. SQL server 查询语句 练习题

    用SQL语句创建四个表: create database tongjigouse tongjigocreate table student(Sno varchar(20) not null prima ...

  4. Canvas入门笔记-实现极简画笔

    今天学习了Html5 Canvas入门,已经有大神写得很详细了http://www.cnblogs.com/tim-li/archive/2012/08/06/2580252.html#8 在学习过后 ...

  5. Java编程思想读书笔记_第6章(访问权限)

    四种访问权限: public private 包访问权限 protected 如果没有明确指定package,则属于默认包 package access.dessert; public class C ...

  6. CF864D Make a Permutation!

    思路: 贪心,构造,模拟. 实现: #include <bits/stdc++.h> using namespace std; ], a[], vis[], n; int main() { ...

  7. Java 基础入门随笔(7) JavaSE版——面向对象定义、特征:封装、构造函数

    面向对象 面向过程:对于面向过程思想,强调的是过程(动作). 面向对象:对于面向对象思想,强调的是对象(实体). 特点: 1,面向对象就是一种常见的思想.符合人们的思考习惯.2,面向对象的出现,将复杂 ...

  8. 判断点击第几个按钮JS代码的三种方法

    方法一:使用下标实现<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> < ...

  9. CAD得到范围内实体(网页版)

    主要用到函数说明: IMxDrawSelectionSet::Select 构造选择集.详细说明如下: 参数 说明 [in] MCAD_McSelect Mode 构造选择集方式 [in] VARIA ...

  10. CAD利用Select2得到所有实体(网页版)

    主要用到函数说明: IMxDrawSelectionSet::Select2 构造选择集.详细说明如下: 参数 说明 [in] MCAD_McSelect Mode 构造选择集方式 [in] VARI ...