Codeforces #427 Div2 D
#427 Div2 D
题意
给出一个字符串,求它的子串中为 \(k-palindrome\) 的个数。
\(1-palindrome\) 要求是一个回文串。
\(k-palindrome (k > 1)\)满足以下条件:
- 是一个回文串
- 它的左右两边是一个不为空的 \((k - 1)-palindromes\) 。
分析
求字符串回文子串个数是一个很经典的题目了,这题变化也不大。
\(dp[i]\) 表示以当前字符结尾的长度为 \(i\) 的字符串 \(k\) 的最大值。
注意 \(2-palindrome\) 同时也是 \(1-palindrome\) 。
code
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
char s[5005];
int dp[5005];
int ans[5005];
int main() {
scanf("%s", s + 1);
int len = strlen(s + 1);
int sum = 0;
vector<int> v1, v2;
for(int i = 1; i <= len; i++) {
ans[1]++; ans[2]--;
v2.push_back(1);
dp[1] = 1;
if(s[i] == s[i - 1]) {
v2.push_back(2);
ans[1]++; ans[2]--;
ans[2]++; ans[3]--;
dp[2] = 2;
}
for(int j = 0; j < v1.size(); j++) {
int l = v1[j];
if(s[i - l - 1] == s[i]) {
v2.push_back(l + 2);
dp[l + 2] += dp[l / 2 + 1] + 1;
ans[1]++; ans[dp[l + 2] + 1]--;
}
}
memset(dp, 0, sizeof dp);
v1 = v2;
v2.clear();
}
for(int i = 1; i <= len; i++) {
ans[i] += ans[i - 1];
}
for(int i = 1; i <= len; i++) {
printf("%d%c", ans[i], " \n"[i == len]);
}
return 0;
}
Codeforces #427 Div2 D的更多相关文章
- Codeforces #180 div2 C Parity Game
// Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...
- Codeforces #541 (Div2) - E. String Multiplication(动态规划)
Problem Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...
- Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)
Problem Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...
- Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)
Problem Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...
- Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)
Problem Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...
- 【Codeforces #312 div2 A】Lala Land and Apple Trees
# [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...
- codeforces round #427 div2
A:读懂题,乘一下判断大小就行了 #include<bits/stdc++.h> using namespace std; int main() { int s, v1, v2, t1, ...
- Codeforces #263 div2 解题报告
比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注冊的时候非常想好好的做一下,可是网上喝了个小酒之后.也就迷迷糊糊地看了题目,做了几题.一觉醒来发现r ...
- codeforces #round363 div2.C-Vacations (DP)
题目链接:http://codeforces.com/contest/699/problem/C dp[i][j]表示第i天做事情j所得到最小的假期,j=0,1,2. #include<bits ...
随机推荐
- 对C++ templates类模板的几点补充(Traits类模板特化)
前一篇文章<浅谈C++ templates 函数模板.类模板以及非类型模板参数>简单的介绍了什么是函数模板(这个最简单),类模板以及非类型模板参数.本文对类模板再做几点补充. 文章目录1. ...
- 图解WinXP局域网共享设置步骤
原文链接地址:http://blog.csdn.net/jackinzhou/article/details/8468208 第一章:共享的前提工作 1.更改不同的计算机名,设置相同的工作组! 2.我 ...
- [Leetcode] word break 拆分词语
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separa ...
- 解析Mybaits的insert方法返回数字-2147482646的原因
前言:前几天在做项目demo的时候,发现有一个很奇怪的现象,就是MyBatis发现更新和插入返回值一直为"-2147482646".无论怎么改,这个值一直不变...是在摸不着头脑, ...
- Codeforces Round #534 (Div. 2) D. Game with modulo(取余性质+二分)
D. Game with modulo 题目链接:https://codeforces.com/contest/1104/problem/D 题意: 这题是一个交互题,首先一开始会有一个数a,你最终的 ...
- POJ1797:Heavy Transportation(改造Dijkstra)
Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 52728 Accepted: ...
- nginx proxy_buffer_size 解决后端服务传输数据过多,其实是header过大的问题
nginx proxy_buffer_size 解决后端服务传输数据过多,其实是header过大的问题 这三个参数已设置就搞定了额 proxy_buffer_size 64k; proxy_buffe ...
- [bzoj1031][JSOI2007]字符加密Cipher——后缀数组
Brief Description 给定一个长度为n的字符串,你需要对其进行加密. 把字符串围成一个环 显然从任意一个位置开始都可以有一个长度为n的串 把产生的n个串按字典序排序,把这n个串的最后一个 ...
- Splunk笔记
学习Splunk Fundamentals Part 2 (IOD) 和 Splunk Fundamentals Part 1课程的笔记. Chart Over By Tips: ….|chart c ...
- 美团网技术团队分享的MySQL索引及慢查询优化教程
MySQL凭借着出色的性能.低廉的成本.丰富的资源,已经成为绝大多数互联网公司的首选关系型数据库.虽然性能出色,但所谓“好马配好鞍”,如何能够更好的使用它,已经成为开发工程师的必修课,我们经常会从职位 ...