CodeForces 835D - Palindromic characteristics | Codeforces Round #427 (Div. 2)
证明在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)的更多相关文章
- [加强版] Codeforces 835D Palindromic characteristics (回文自动机、DP)
题目链接: https://codeforces.com/contest/835/problem/D 题意: 一个回文串是\(1\)-回文的,如果一个回文串的左半部分和右半部分一样且都是\(k\)-回 ...
- CodeForces 835C - Star sky | Codeforces Round #427 (Div. 2)
s <= c是最骚的,数组在那一维开了10,第八组样例直接爆了- - /* CodeForces 835C - Star sky [ 前缀和,容斥 ] | Codeforces Round #4 ...
- 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 ...
- 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 ...
- Codeforces Round #427 (Div. 2)—A,B,C,D题
A. Key races 题目链接:http://codeforces.com/contest/835/problem/A 题目意思:两个比赛打字,每个人有两个参数v和t,v秒表示他打每个字需要多久时 ...
- 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) D dp
D. Palindromic characteristics time limit per test 3 seconds memory limit per test 256 megabytes inp ...
- 【Codeforces Round #427 (Div. 2) D】Palindromic characteristics
[Link]:http://codeforces.com/contest/835/problem/D [Description] 给你一个字符串; 让你在其中找到1..k阶的回文子串; 并统计它们的数 ...
- Codeforces Round #427 (Div. 2) D - Palindromic characteristics
本题是个简单的区间dp 最近都没时间做题了,被我妈强制喊回去,然后颓废了10天(回家也没发控制住自己= = 我的锅),计划都打乱了,本来还报名了百度之星,然后没时间参加 #include<cma ...
随机推荐
- (十四)springMvc 对 restful 的支持
文章目录 restful 的概念 配置支持 restful 的前端控制器 配置不拦截静态资源 restful 的概念 restful 是一种开发理念: 对 url 进行规范 每个 url 代表一个资源 ...
- A<=B的前提下全排列A使答案尽量大
题意:http://codeforces.com/problemset/problem/915/C 举个例子:假使排好序后a字符串是123456,b是456456,按照上述方法遍历,213456 -& ...
- 网络编程[第三篇]基于tcp协议实现远程连接
需要用到subprogress模块来远程控制cmd控制台程序来得到控制台的输出信息 一.服务端 —— 控制输出信息 import socket import subprocess #socket实例化 ...
- 二进制协议gob和msgpack介绍
二进制协议gob和msgpack介绍 本文主要介绍二进制协议gob及msgpack的基本使用. 最近在写一个gin框架的session服务时遇到了一个问题,Go语言中的json包在序列化空接口存放的数 ...
- 牛客 26C 手铐 (缩环, 树形dp)
先缩环建树, 对于树上个环$x,y$, 假设$x,y$路径上有$cnt$个环(不包括$x,y$), 贡献就为$2^{cnt}$. 这题卡常挺严重的, 刚开始用并查集合并竟然T了. #include & ...
- 利用Mathpix Snipping Tool轻松在markdown/LaTeX中输入电子书和论文的数学公式
最近写图形学博客写累了,公式太多了,一个个输入实在太累,所以从数学建模队友那里吃了一个安利. 官网下载 下载安装后,直接新建一个截图,就可以转成LaTeX数学公式了.效果如下: 爽的一批啊!!! 另外 ...
- 设计模式 -- MVC
MVC 在Web中应用是常见的了,成为基础应用模式. 不好的用法是把业务写在C 中,M只是失血模型. 应该要重M 轻C,业务写在M中,但是这样有问题了.View 会引用Model,那么View会看到M ...
- JS中逗号运算符的用法
逗号运算符,它将先计算左边的参数,再计算右边的参数值.然后返回最右边参数的值. 原书举的例子不太好,无法解释上面那句话,这里另外提供一个: var a = 10, b = 20; function C ...
- java中long类型转换为int类型
由int类型转换为long类型是向上转换,可以直接进行隐式转换,但由long类型转换为int类型是向下转换,可能会出现数据溢出情况: 主要以下几种转换方法,供参考: 一.强制类型转换 [java] l ...
- CSS 实现居中 + 清除浮动
一.水平居中 1.行内元素:text-align:center; 2.块级元素:margin:0 auto; 3.绝对定位和移动:absolute + transform 4.绝对定位和负边距:abs ...