证明在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. html当中如何引用js文件

    3)html当中如何引用js文件 如果需要javascript工程师和html美工各干各的工作,需要分开写文件. 例 1.2 <html><head>    <scrip ...

  2. mysql8.0.13下载与安装图文教程

    一.进入mysql网站:https://dev.mysql.com/downloads/mysql/ 二.进入Community选择MySQL Communtiy Server 三.将页面拉到最下面选 ...

  3. jQuery获取当前checkbox的值

    背景: 目前想实现登录的“记住我”功能,需要获取当前checkbox是否被点击,百度了一通,全是多个复选框选中了哪一个的解答, 迫于无奈,自己在W3school上面查询了checkbox的所有属性,并 ...

  4. linux下如何查看一个服务所在的安装路径?

    当接手一个不是自己维护的linux服务器,我们常常会想要看看该服务器上是否安装了某个服务,这个服务安装的路径在哪? redis 是开发过程中常常会用到的一个服务,我这里就以这个服务为例,进行说明. 1 ...

  5. Excel2016 保存\复制 卡死问题解决

    遇到的问题: 工作中经常碰到一些Excel表, 复制一行, 再粘贴要等5s以上才能显示成功. 保存一下文档, 也会出现页面白屏卡死的情况, 经过网上多个帖子进行操作依旧无解, 最后找到了自己的方法得以 ...

  6. MyBatis 源码篇-Transaction

    本章简单介绍一下 MyBatis 的事务模块,这块内容比较简单,主要为后面介绍 mybatis-spring-1.**.jar(MyBatis 与 Spring 集成)中的事务模块做准备. 类图结构 ...

  7. beego 参数配置

    详细配置请参考:https://godoc.org/github.com/astaxie/beego#pkg-constants. App配置 AppName 应用名称,默认是 beego.通过bee ...

  8. 浅谈hashcode

    哈希表这个数据结构想必大多数人都不陌生,而且在很多地方都会利用到hash表来提高查找效率.在Java的Object类中有一个方法: 1 public native int hashCode(); 根据 ...

  9. Spring mvc 参数半丁

    http://blog.csdn.net/eson_15/article/details/51718633 众所周知,springmvc是用来处理页面的一些请求,然后将数据再通过视图返回给用户的,前面 ...

  10. excel 导入

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