题目链接:http://codeforces.com/contest/835/problem/D

题意:给定一个字符串,定义kth回文是左半部分等于右半部分,并且左半部分和右半部分都是(k-1)th回文。 只要是回文字串都是1th回文。 对于1<=k<=strlen(s),输出kth回文的数量。

思路:预处理出每个子串是否是回文。然后len^2枚举区间,如果s[i][j]是回文的话,继续枚举左半部分s[i][i+(j-i+1)/2-1]是否是回文,是的话再继续枚举左半部分然后顺便统计答案即可。 对于统计贡献,假设s[i][j]连续枚举了x次左半部分都是回文,第x+1次的左半部分不是回文,则说明s[i][j]是xth回文, s[i][j]的左半部分是x-1th回文....相当于把(1~x)th贡献+1,代码里是逆着算贡献即xth回文算到1th中,但是并不影响最后对答案的贡献

#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<time.h>
#include<cmath>
#include<set>
#include<map>
using namespace std;
typedef long long int LL;
const int MAXN = + ;
const int INF = 1e9;
const int mod = 1e9 + ;
char str[MAXN];
LL ans[MAXN];
bool isPalind[MAXN][MAXN];
void Make_Palind(int len){
for (int i = ; i < len; i++) {
int l = i, r = i;
for (int l = i, r = i; l >= && r < len&&str[l] == str[r]; l--, r++){ //奇长度回文
isPalind[l][r] = true;
}
for (int l = i, r = i + ; l >= && r < len&&str[l] == str[r]; l--, r++){ //偶长度回文
isPalind[l][r] = true;
}
}
} int main(){
#ifdef kirito
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
while (~scanf("%s", str)){
int len = strlen(str);
memset(ans, , sizeof(ans));
memset(isPalind, false, sizeof(isPalind));
Make_Palind(len);
for (int i = ; i < len; i++){
for (int j = i; j < len; j++){
for (int l = i, r = j, k = ; l >= && r < len && r >= l && isPalind[l][r]; r = l + (r - l + ) / - , k++){
ans[k]++;
}
}
}
for (int i = ; i <= len; i++){
printf("%lld%c", ans[i], (i == len ? '\n' : ' '));
}
}
return ;
}

Codeforces Round #427 (Div. 2) - D的更多相关文章

  1. CodeForces 835C - Star sky | Codeforces Round #427 (Div. 2)

    s <= c是最骚的,数组在那一维开了10,第八组样例直接爆了- - /* CodeForces 835C - Star sky [ 前缀和,容斥 ] | Codeforces Round #4 ...

  2. CodeForces 835D - Palindromic characteristics | Codeforces Round #427 (Div. 2)

    证明在Tutorial的评论版里 /* CodeForces 835D - Palindromic characteristics [ 分析,DP ] | Codeforces Round #427 ...

  3. 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 ...

  4. Codeforces Round #427 (Div. 2) Problem C Star sky (Codeforces 835C) - 前缀和

    The Cartesian coordinate system is set in the sky. There you can see n stars, the i-th has coordinat ...

  5. Codeforces Round #427 (Div. 2) Problem A Key races (Codeforces 835 A)

    Two boys decided to compete in text typing on the site "Key races". During the competition ...

  6. Codeforces Round #427 (Div. 2) B. The number on the board

    引子: A题过于简单导致不敢提交,拖拖拉拉10多分钟还是决定交,太冲动交错了CE一发,我就知道又要错过一次涨分的机会.... B题还是过了,根据题意目测数组大小开1e5,居然蒙对,感觉用vector更 ...

  7. Codeforces Round #427 (Div. 2)—A,B,C,D题

    A. Key races 题目链接:http://codeforces.com/contest/835/problem/A 题目意思:两个比赛打字,每个人有两个参数v和t,v秒表示他打每个字需要多久时 ...

  8. Codeforces Round #427 (Div. 2)——ABCD

    http://codeforces.com/contest/835 A.拼英语水平和手速的签到题 #include <bits/stdc++.h> using namespace std; ...

  9. 【Codeforces Round #427 (Div. 2) D】Palindromic characteristics

    [Link]:http://codeforces.com/contest/835/problem/D [Description] 给你一个字符串; 让你在其中找到1..k阶的回文子串; 并统计它们的数 ...

  10. 【Codeforces Round #427 (Div. 2) A】Key races

    [Link]:http://codeforces.com/contest/835/problem/A [Description] [Solution] 傻逼题. [NumberOf WA] [Revi ...

随机推荐

  1. hg(Mercurial)使用参考

    hg(Mercurial)使用参考   使用hg(mercurial)有好几个月了,个人感觉这款分布式的版本控制系统非常不错,易学,易用:你可以从做在你旁边的同事拉取完整的代码; 对网络的依赖性更低, ...

  2. MySQL表碎片清理

    MySQL大表清理 生产环境data库业务表base_data大小:500G,data_free:31G mysql> SELECT table_schema,table_name,data_f ...

  3. 【洛谷T89359 扫雷】

    题目链接 这个题有一个十分简单的做法 我们可以考虑位运算 按位异或(^) 异或,英文为exclusive OR,缩写成xor 异或(xor)是一个数学运算符.它应用于逻辑运算.异或的数学符号为“⊕”, ...

  4. Octavia 项目加速 OpenStack LBaaS 落地大规模应用场景

    目录 文章目录 目录 OpenStack LBaaS Octavia 软件架构 网络架构 操作对象基本概念 功能实现基本概念 Ocatvia Daemon 列表 部署 Ocatvia 手动方式集成 O ...

  5. 阶段3 1.Mybatis_09.Mybatis的多表操作_4 完成account一对一操作-建立实体类关系的方式

    定义user的实体.然后生成getter和setter 定义一个可以封装Account和User的Map type这里虽然是account类型 这一段只能保证account的数据完成.并不能保证use ...

  6. 日常linux命令

    绝对路径用什么符号表示?当前目录.上层目录用什么表示?主目录用什么表示? 切换目录用什么命令?   绝对路径: 如/etc/init.d                当前目录和上层目录: ./  . ...

  7. C#SQL小结

    对于c#获取Sql数据目前我采用的是 System.Data.SqlClient.SqlDataReader类. 主要用到如下API: SqlDataReader.Read():每次获取一行的数据,直 ...

  8. MySQL-快速入门(12)备份、还原

    1.数据备份 1>使用MySQLdump命令备份(主要的方式) //备份数据库中某张表(去掉表的限定,就是备份指定数据库)//备份脚本可以重新创建表及插入数据mysqldump -u user ...

  9. vue点击除了某组件本身的其它地方, 隐藏该组件的方法

    点击emoji表情标签, 出现标签组件,点击其它地方, 改组件消失的效果; <template> <div class="writeZoon"> <d ...

  10. steps 步骤条、时间轴

    steps 步骤条.时间轴:http://www.fxss5201.cn/project/plugin/steps/1.0/ Github地址:https://github.com/fxss5201/ ...