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. Hibernate 5 入门指南-基于Envers

    首先创建\META-INF\persistence.xml配置文件并做简单的配置 <persistence xmlns="http://java.sun.com/xml/ns/pers ...

  2. Linux: 软件包管理之rpm与yum [转]

    软件包的安装和卸载时很平常的事,但在Linux上面却不简单..Linux的其中一个哲学就是一个程序只做一件事,并且做好.组合小程序来完成复杂的任务,这样做有很多好处,但是各个小程序之间往往会存在着复杂 ...

  3. LeetCode算法题-Binary Tree Paths(Java实现-3种解法)

    这是悦乐书的第199次更新,第206篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第62题(顺位题号是257).给定二叉树,返回所有根到叶路径.例如: 输入: 1 / \ ...

  4. 设计模式のVisitorPattern(访问者模式)----行为模式

    一.产生背景 访问者模式是封装一些施加于某种数据结构之上的操作.一旦这些操作需要修改的话,接受这个操作的数据结构则可以保存不变.访问者模式适用于数据结构相对稳定的系统, 它把数据结构和作用于数据结构之 ...

  5. 使用chrome远程调试设备及调试模拟器设备

    使用chrome开发工具远程在Android上远程调试 准备工作 开始远程调试之前,需要做好如下准备: 在你电脑上安装Chrome 32 或者更新的版本 一根连接Android设备的USB线 手机系统 ...

  6. focus()无效问题

    我想点击弹出一个控件的时候控件里的input自动获取焦点,INPUT的class为"group-input",可用下面的写法不行: document.queryselect(&qu ...

  7. Python中关于if __name__=='__main__'的问题

    先举一个简单的例子: 这里有两个.py的文件,a.py和b.py a.py内容为: b.py的内容为: 当执行b.py时结果为: 也就是将a.py文件里的内容执行一边,b.py里的内容执行一边,这显然 ...

  8. 001_HTTP参数中Etag的重要性

    在研究tornado时,有个Etag比较好奇,从网上查询摘录如下:

  9. 深度学习框架PyTorch一书的学习-第四章-神经网络工具箱nn

    参考https://github.com/chenyuntc/pytorch-book/tree/v1.0 希望大家直接到上面的网址去查看代码,下面是本人的笔记 本章介绍的nn模块是构建与autogr ...

  10. hyperledge工具-configtxlator

    参考:http://www.blockchainbrother.com/article/1337 1.作用: 因为无论配置交易文件 .tx和初始区块文件 .block都是二进制格式,用户无法直接编辑. ...