Codeforces 835D-Palindromic characteristics

Palindromic characteristics
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 tdivided 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..k阶的回文子串并统计它们的数量。如果一个字符串是一个回文串,则它可以是1阶子串(k阶字符串,要求它的左边和右边都是k-1阶子串)

解题思路:dp[i][j]用来记录这段字符串是几阶子串即可


#include <iostream>  
#include <cstdio>  
#include <cstring>  
#include <string>  
#include <algorithm>  
#include <map>  
#include <set>  
#include <stack>  
#include <queue>  
#include <vector>  
#include <bitset>  
#include <functional>

using namespace std;

#define LL long long  
const int INF = 0x3f3f3f3f;

char ch[5009];
int ans[5009],dp[5009][5009];

int main()
{
	while (~scanf("%s", ch+1))
	{
		int len = strlen(ch+1);
		memset(ans, 0, sizeof ans);
		memset(dp, 0, sizeof dp);
		for (int i = 1; i <= len; i++)
		{
			dp[i][i] = 1;
			ans[1]++;
			if (i < len&&ch[i] == ch[i + 1]) dp[i][i + 1] = 2, ans[2]++,ans[1]++;
		}
		for (int i = 3; i <= len; i++)
			for (int j = 1; j + i - 1 <= len; j++)
				if (dp[j + 1][j + i - 2] && ch[j] == ch[i + j - 1])
				{
					dp[j][j + i - 1] = dp[j][j+i/2-1]+1;
					for (int k = 1; k <= dp[j][j + i - 1]; k++) ans[k]++;
				}
		printf("%d", ans[1]);
		for (int i = 2; i <= len; i++) printf(" %d", ans[i]);
		printf("\n");
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值