证明在Tutorial的评论版里

/*
CodeForces 835D - Palindromic characteristics [ 分析,DP ] | Codeforces Round #427 (Div. 2)
题意:
定义 k 回文串满足:
1. 左右子串相等
2. 左右子串为k-1回文串
1 回文串 就是回文串
问你字符串s的子串的每阶回文子串的数目
分析:
研究一下可以发现 k 回文串的要求等价于
1. 本身是回文串
2. 左右子串是k-1回文串
然后可以dp了,还有一个结论是:
若一个串是 k 回文,那它一定是 k-1 回文
方便最后统计
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
char s[N];
int len;
int dp[N][N], ans[N];
void init()
{
int l;
for (int i = 0; i < len; i++)
{
l = 0;
while (i-l >= 0 && i+l < len && s[i-l] == s[i+l])
{
dp[i-l][i+l] = 1; ++ans[1];
++l;
}
l = 0;
while (i-l >= 0 && i+l+1 < len && s[i-l] == s[i+l+1])
{
dp[i-l][i+l+1] = 1; ++ans[1];
++l;
}
}
}
void solve()
{
for (int k = 2; k <= len; k++)
{
for (int i = 0; i < len; i++)
{
int j = i+k-1;
int mid = i+k/2-1;
if (dp[i][mid] && dp[i][j])
{
dp[i][j] = max(dp[i][j], dp[i][mid]+1);
ans[dp[i][j]]++;
}
}
}
}
int main()
{
scanf("%s", s);
len = strlen(s);
init();
solve();
for (int i = len; i >= 2; i--)
ans[i] += ans[i+1];
for (int i = 1; i <= len; i++)
printf("%d ", ans[i]);
puts("");
}

update*修改了错误的代码

CodeForces 835D - Palindromic characteristics | Codeforces Round #427 (Div. 2)的更多相关文章

  1. [加强版] Codeforces 835D Palindromic characteristics (回文自动机、DP)

    题目链接: https://codeforces.com/contest/835/problem/D 题意: 一个回文串是\(1\)-回文的,如果一个回文串的左半部分和右半部分一样且都是\(k\)-回 ...

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

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

  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) [ C. Star sky ] [ D. Palindromic characteristics ] [ E. The penguin's game ]

    本来准备好好打一场的,然而无奈腹痛只能带星号参加 (我才不是怕被打爆呢!) PROBLEM C - Star sky 题 OvO http://codeforces.com/contest/835/p ...

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

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

  6. Palindromic characteristics CodeForces - 835D (区间DP,预处理回文串问题)

    Palindromic characteristics of string s with length |s| is a sequence of |s|integers, where k-th num ...

  7. Codeforces Round #427 (Div. 2) D dp

    D. Palindromic characteristics time limit per test 3 seconds memory limit per test 256 megabytes inp ...

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

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

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

    本题是个简单的区间dp 最近都没时间做题了,被我妈强制喊回去,然后颓废了10天(回家也没发控制住自己= = 我的锅),计划都打乱了,本来还报名了百度之星,然后没时间参加 #include<cma ...

随机推荐

  1. (六)mybatis 全局配置文件讲解

    目录 properties (属性) settings 全局参数配置 typeAliases 别名设置 typeHandlers 类型处理器 mapper (映射器) 细节 properties (属 ...

  2. Python补充4——替换与修改

    最近在自学Python ,在学习过程中发现一个问题,就是Python 的替换与修改. 按照中文思维,替换与修改有什么区别吗?如果发生了部分替换不就是修改了吗?如果修改了不就是新对象替换了老对象吗? 实 ...

  3. HTTP协议探究(四):TCP和TLS优化

    一 复习与目标 1 复习 简单密码学.对称加密与非对称加密 数字签名.数字证书 SSL/TLS HTTPS = HTTP + SSL/TLS,SSL/TLS为HTTP提供了保密性.完整性和鉴别性 2 ...

  4. HTTP协议探究(序章)

    1 HTTP协议基于TCP协议 (1)TCP三次握手连接 HTTP客户端(Chrome浏览器): IP:192.168.1.47 端口:59875 MSS:1460 HTTP服务器(Nginx服务器) ...

  5. excel 导入

    public static DataTable ExcelToDataTable(string fileName, string sheetName, bool isFirstRowColumn) { ...

  6. 关于SpringBoot的自动配置和启动过程

    一.简介 Spring Boot简化了Spring应用的开发,采用约定大于配置的思想,去繁从简,很方便就能构建一个独立的.产品级别的应用. 1.传统J2EE开发的缺点 开发笨重.配置繁多复杂.开发效率 ...

  7. MySQL cmd操作

    1.开启关闭服务 net start mysql net stio mysql 2.登陆 在CMD命令窗口敲入命令 mysql -hlocalhost -uroot -p 后按回车(注意这里的&quo ...

  8. Linux文件的管理

    创建:touch  vim/vi  echo重定向  cat touch 管理: atime  mtime touch  文件名  //如果文件不存在,不创建文件 删除:mv /tmp find |x ...

  9. 2.Bacula Server端安装配置

    1.  Bacula Server端安装配置 1.1.  Bacula Server端安装 1.1.1.  安装bacula依赖包 For Centos6: yum install -y mysql ...

  10. 04_Hive的基本命令

    1.Hive基本操作: 1.1.Hive的建表语句: CREATE [EXTERNAL] TABLE [IF NOT EXISTS] table_name [(col_name data_type [ ...