题目链接: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. 使用Vue前端框架实现知乎日报app

    这是:主页代码 <template> <view class="content"> <view class="uni-list"& ...

  2. c/c++运算符

    1.算术运算符(+  -  /  *  %) 2.移位运算符 移运算符:操作数必须是整形,>>,逻辑左移左边移入的位用0填充,算数左移左边移入的的位用符号位补齐.(无符号数为逻辑左移,对于 ...

  3. git && github 相关

    权限问题(error: The requested URL returned error: 403 Forbidden while accessing):1. 将自己机器的ssh public key ...

  4. leetcode-mid- 50. Pow(x,n)-NO

    mycode  time limited 例如 x=0.00001 n=2147483647 参考: class Solution(object): def myPow(self, x, n): &q ...

  5. Python基本语法_基本数据类型_数值型详解

    目录 目录 软件环境 Python变量调用的过程 数值型 删除一个数值类型对象 布尔型 Bool 标准整型 Int 长整型 双精度浮点型 Float 复数 数值类型对象的内建功能函数 absNumbe ...

  6. 阶段3 1.Mybatis_06.使用Mybatis完成DAO层的开发_5 Mybatis中使用Dao实现类的执行过程分析-查询方法1

    继续运行testFindAll方法.把其他类的断点都删除掉. 只在这里加了断点,所以直接就跳转到这里了.RoutingStatementHandler里面的query方法 继续往下走,断点又回到了这里 ...

  7. 系统分析与设计HW1

    软件工程的定义 1993年,电气电子工程师学会(IEEE)给出了一个定义:"将系统化的.规范的.可度量的方法用于软件的开发.运行和维护的过程,即将工程化应用于软件开发中". 阅读经 ...

  8. flask如何实现https以及自定义证书的制作

    http://blog.csdn.net/yannanxiu/article/details/70672744 http://blog.csdn.net/yannanxiu/article/detai ...

  9. virtualbox压缩虚拟机硬盘文件vhd

    命令如下: VBoxManage modifyhd D:\pc1\pc1.vhd  --compact 当提示以下内容时,将整个虚拟机文件夹拷贝盘符根目录下,将[D:\pc1\pc1.vhd]改为相应 ...

  10. springBoot(1) 环境安装

    真鸡儿要命.今天做开发.实在是整不动了...所以决定回家,干一波... 发现MyEclipse2014好像真的不用能用了... 瞬间焦头烂额,本来,就跑不了.现在环境也没一个能用的. 于是 就有了今天 ...