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.

题意:

给定一个字符串,定义字符串的等级如下:

如果一个字符串是回文串,那么等级为1

如果他的左半边的字符串和右半边的字符串也都是回文串,那么等级为2.

如果他左半边的左半边和右半边是回文串,右边同,那么等级为3.

以此类推。。。。。

让求这个字符串的所有连续子串的等级情况,

你只需要输出等级为1~n的子串的个数就ok了。

思路:

用区间DP,n*n处理字符串,即dp[i][j] =1 则代表字符串s 中,s[i~j] 是一个回文串。

而数组f[i][j] 代表 s[i~j]的等级。

细节见代码,有详细的注释。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1ll;while(b){if(b&)ans=ans*a%MOD;a=a*a%MOD;b>>=;}return ans;}
inline void getInt(int* p);
const int maxn=;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
char s[maxn];
int cnt[maxn];
const int N = 5e3+;
int dp[N][N];
int f[N][N];
int main()
{
// freopen("C:\\Users\\DH_M\\Desktop\\code_io\\in.txt.txt","r",stdin);
// freopen("C:\\Users\\DH_M\\Desktop\\code_io\\out.txt.txt","w",stdout);
scanf("%s",s+);
int len=strlen(s+);
repd(i,,len)
{
dp[i][i]=dp[i][i-]=;// dp[i][i] 长度为1的字符串肯定是回文串,而dp[i][i-1]=1 是因为在区间DP转移的时候要用到。
f[i][i]=;// 长度为1的串肯定只能是1等级的字符串
}
cnt[]+=len;// len个长度为1 的字符串加到等级为1的中
repd(k,,len)// k 这里是枚举子串的长度
{
// len = 5
// 1 2 3 4 5
// 1 5
// 1 2
repd(i,,len+-k)
{
int j=i+k-;// 区间的左区间
dp[i][j]=dp[i+][j-]&(s[i]==s[j]);// 转移过程用到的”与“运算
// 因为s[i]~s[j] 想要是回文串,那么要在s[i+1]~s[j-1]是回文串的基础上,s[i]==s[j]
// 这里长度为2的时候就要用到dp[i][i-1]=1
f[i][j]=dp[i][j] ? f[i][(i+j-)/]+:;// 等级转移,
// 首先判断是不是回文串,如果不是,等级只能为0
// 如果是回文串,那么这个字符串的等级为他的左半边字符串的等级+1
cnt[f[i][j]]++;// 在答案数组中加一下
}
}
for(int i=len;i>=;i--)
{
cnt[i]+=cnt[i+];// 处理下答案数组,因为i+1等级的字符串一定也满足i等级
}
repd(i,,len)
{
printf("%d ",cnt[i] );// 输出答案
}
// Input
// abba
// Output
// 6 1 0 0
return ;
} inline void getInt(int* p) {char ch;do {ch = getchar();}
while (ch == ' ' || ch == '\n');if (ch == '-') {*p = -(getchar() - '');
while ((ch = getchar()) >= '' && ch <= '') {*p = *p * - ch + '';}}
else {*p = ch - '';while ((ch = getchar()) >= '' && ch <= '')
{*p = *p * + ch - '';}}}

Palindromic characteristics CodeForces - 835D (区间DP,预处理回文串问题)的更多相关文章

  1. HDU 4632 Palindrome subsequence(区间dp,回文串,字符处理)

    题目 参考自博客:http://blog.csdn.net/u011498819/article/details/38356675 题意:查找这样的子回文字符串(未必连续,但是有从左向右的顺序)个数. ...

  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. HDU 4632 CF 245H 区间DP(回文)

    先说HDU 4632这道题,因为比较简单,题意就是给你一个字符串,然后给你一个区间,叫你输出区间内所有的回文子序列,注意是回文子序列,不是回文字串. 用dp[i][j]表示区间[i,j]内的回文子序列 ...

  4. HDU 4632 Palindrome subsequence(区间DP求回文子序列数)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4632 题目大意:给你若干个字符串,回答每个字符串有多少个回文子序列(可以不连续的子串).解题思路: 设 ...

  5. 牛客练习赛64 如果我让你查回文你还爱我吗 线段树 树状数组 manacher 计数 区间本质不同回文串个数

    LINK:如果我让你查回文你还爱我吗 了解到了这个模板题. 果然我不会写2333... 考试的时候想到了一个非常辣鸡的 线段树合并+莫队的做法 过不了不再赘述. 当然也想到了manacher不过不太会 ...

  6. CF452F等差子序列 & 线段树+hash查询区间是否为回文串

    记录一下一个新学的线段树基础trick(真就小学生trick呗) 给你一个1到n的排列,你需要判断该排列内部是否存在一个3个元素的子序列(可以不连续),使得这个子序列是等差序列.\(n\) <= ...

  7. leetcode 5 Longest Palindromic Substring(Manacher算法求最长回文串)

    应用一下manacher算法就可以O(n)求出结果了.可以参考hdu3068 substr(start,length)函数是这样用的: substr 方法 返回一个从指定位置开始,并具有指定长度的子字 ...

  8. [LeetCode] Palindrome Partitioning II 拆分回文串之二

    Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...

  9. UVA 11584 Partitioning by Palindromes 划分回文串 (Manacher算法)

    d[i]表示前面i个字符划分成的最小回文串个数, 转移:当第i字符加进来和前面区间j构成回文串,那么d[i] = d[j]+1. 要判断前面的字符j+1到i是不是回文串,可以用Manacher算法预处 ...

随机推荐

  1. java开发基础知识学习

    java环境配置 classpath: .当前目录 path: java 命令所在目录 jdk安装目录 jdk/bin jre安装目录 jre/bin 安装JDK后配置环境变量如下: 安装过程用到了j ...

  2. HDU ACM 1690 Bus System (SPFA)

    Bus System Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  3. Syntax error, parameterized types are only available if source level is 1.5 解决方案

    在网上找了一个K-means算法的程序,打开,运行,出现了Syntax error,parameterized types are only available if source level is ...

  4. 【工匠大道】升级Mac下的svn,解决命令行不能使用svn的问题

    本文地址 原文地址 一. 为什么要升级SVN? 因为MAC上默认安装的是1.6版本,在使用时经常会提示SVN版本太旧,所以一定要升级 二. 怎么升级? 所有软件安装都是这三步吧,哈哈 第一步: 下载 ...

  5. 《Java大学教程》--第1章 步入Java世界

    1.2 软件:用于计算机执行的指令的集合称之为程序(program).单个程序或者一组程序称之为软件(software)1.3 编译:计算机的语言称为机器码(machine code).用编译器(co ...

  6. FastJSON、Gson和Jackson性能对比

    Java处理JSON数据有三个比较流行的类库FastJSON.Gson和Jackson.本文将测试这三个类库在JSON序列化和反序列化的方面表现,主要测试JSON序列化和反序列化的速度.为了防止由于内 ...

  7. 【HNOI2016】大数

    [HNOI2016]大数 题目链接 题目描述 小 B 有一个很大的数 $ S $,长度达到了 $ N $ 位:这个数可以看成是一个串,它可能有前导 $ 0 $,例如 00009312345 .小 B ...

  8. 【vue】vue +element 搭建项目,将js函数变成vue的函数

    demo:时间转换 1.目录 <1>在src文件夹下新建文件夹prototypefns--------在此文件夹创建util.js, <2>在prototypefns下新建文件 ...

  9. JS学习实践(1) JavaScript 修改图像灯泡

    修改灯泡 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <titl ...

  10. ogg BR – BOUNDED RECOVERY

    BR – BOUNDED RECOVERY 适用于 Extract 进程(仅适用于 Oracle数据库) 使用 BR 参数可以控制 GoldenGate 的 Bounded Recovery (BR) ...