D. Palindromic characteristics
3 seconds
256 megabytes
standard input
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:
- 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.
The first line contains the string s (1 ≤ |s| ≤ 5000) consisting of lowercase English letters.
Print |s| integers — palindromic characteristics of string s.
abba
6 1 0 0
abacaba
12 4 1 0 0 0 0
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的更多相关文章
- Palindromic characteristics CodeForces - 835D (区间DP,预处理回文串问题)
Palindromic characteristics of string s with length |s| is a sequence of |s|integers, where k-th num ...
- 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 ...
- 【CF835D】Palindromic characteristics 加强版 解题报告
[CF835D]Palindromic characteristics 加强版 Description 给你一个串,让你求出\(k\)阶回文子串有多少个.\(k\)从\(1\)到\(n\). \(k\ ...
- CodeForces 835D - Palindromic characteristics | Codeforces Round #427 (Div. 2)
证明在Tutorial的评论版里 /* CodeForces 835D - Palindromic characteristics [ 分析,DP ] | Codeforces Round #427 ...
- 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 ...
- D. Palindromic characteristics 解析(DP)
Codeforce 835 D. Palindromic characteristics 解析(DP) 今天我們來看看CF835D 題目連結 題目 略,請看原題 前言 想不到這種狀態... @copy ...
- Codeforces Round #427 (Div. 2) D - Palindromic characteristics
本题是个简单的区间dp 最近都没时间做题了,被我妈强制喊回去,然后颓废了10天(回家也没发控制住自己= = 我的锅),计划都打乱了,本来还报名了百度之星,然后没时间参加 #include<cma ...
- 【XSY2534】【CF835D】Palindromic characteristics 回文自动机
题目大意 一个字符串\(s\)是\(1\)−回文串当且仅当这个串是回文串. 一个串\(s\)是\(k\)−回文串\((k>1)\)当且仅当\(s\)的前一半与后一半相同且\(s\)的前一 ...
- 【CodeForces】835D Palindromic characteristics
[题意]给你一个串,让你求出k阶回文子串有多少个.k从1到n.k阶子串的定义是:子串本身是回文串,而且它的左半部分也是回文串. [算法]区间DP [题解]涉及回文问题的区间DP都可以用类似的写法,就是 ...
随机推荐
- 数学+DP Codeforces Round #304 (Div. 2) D. Soldier and Number Game
题目传送门 /* 题意:这题就是求b+1到a的因子个数和. 数学+DP:a[i]保存i的最小因子,dp[i] = dp[i/a[i]] +1;再来一个前缀和 */ /***************** ...
- composer windows安装,使用新手入门[转]
原:https://blog.csdn.net/csdn_dengfan/article/details/54912039 一.前期准备: 1.下载安装包,https://getcomposer.or ...
- kafka的topic命名技巧
不多说,直接上干货! 比如,我们给kafka的topic命名为user_r2p10 表示user这个topic的副本因子(r)是2,分区数(p)是10. 这样后期在写消费者代码的时候,根据top ...
- MyElipse如何添加Emmet插件
把这个jar文件放到myeclipse2014安装目录下dropins文件夹中,然后重启myeclipse即可. 可到window-->perferences里查看,如果成功则会看到emmet选 ...
- PLC学习资料
常用字母 X 输入点(I)可连接外部输入信号 如感应器或限位/按钮等M 内部辅助继电器S 内部步进 不作步进使用时,可用作内部辅助继电器T 时间继电器 内部使用C计数器 内部使用Y输出点(O)输出给外 ...
- PSP辅助软件开发计划
PSP辅助软件开发计划 作者: 日期:2013年11月14号 1开发目的 鉴于软件开发过程中,程序员往往无法在规定时间内完成任务,而且无法给出拖延的时间从而造成项目进度计划不准确.开发此软件帮助程序员 ...
- 初始MongoDB------将MongoDB创建为Windows服务
上一遍我写的是关于基本的MongoDB的安装,可能不是很详细,也写得很不好,不过这次我们会详细的说说,如果将MongoDB部署在你的Windows电脑上. 1.配置环境变量 如果每次都要在CMD进入M ...
- CNN:测试一下YoloV3
项目地址:https://pjreddie.com/darknet/yolo/ mAP提升了不少,在VS上试一把 V3 的权值: https://pjreddie.com/media/files/yo ...
- Hive DDL&DML
1.删除分区 ALTER TABLE table_name DROP IF EXISTS PARTITION(dt=') 如果是外部表,记得rm对应文件 2.添加分区 ALTER TABLE tabl ...
- 执行join_paired_ends.py报错Cannot find fastq-join
通过 conda 安装 qiime 1后,在执行join_paired_ends.py时报错: burrito.util.ApplicationNotFoundError: Cannot find f ...