codeforces835D(94/600)

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:

Its left half equals to its right half.
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<bits/stdc++.h>
using namespace std;
int dp[5001][5001];
int dan[5001];
int main()
{
    string q;
    cin>>q;
    int k=q.size();
    for(int a=0;a<k;a++)dp[a][a]=1;
    dan[1]=k;
    for(int a=0;a<k;a++)
    {
        for(int b=a-1;b>=0;b--)
        {
            if(q[a]!=q[b])continue;
            int cd=a-b+1;
            if(cd==2)
            {
                dp[b][a]=2,dan[2]++;                
                continue;
            }
            if(!dp[b+1][a-1])continue;
            if(cd%2)
            {
                int zhong=cd/2;
                zhong+=b;
                dp[b][a]=dp[b][zhong-1]+1;
                dan[dp[b][a]]++;
            }
            else
            {
                int zhong=cd/2;
                zhong+=b;
                zhong--;
                dp[b][a]=dp[b][zhong]+1;
                dan[dp[b][a]]++;
            }
        }
    }
    for(int a=k-1;a>=1;a--)dan[a]+=dan[a+1];
    for(int a=1;a<=k;a++)cout<<dan[a]<<" ";
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章