#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的更多相关文章

  1. Codeforces #180 div2 C Parity Game

    // Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...

  2. Codeforces #541 (Div2) - E. String Multiplication(动态规划)

    Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...

  3. Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)

    Problem   Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...

  4. Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)

    Problem   Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...

  5. Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)

    Problem   Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...

  6. 【Codeforces #312 div2 A】Lala Land and Apple Trees

    # [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...

  7. codeforces round #427 div2

    A:读懂题,乘一下判断大小就行了 #include<bits/stdc++.h> using namespace std; int main() { int s, v1, v2, t1, ...

  8. Codeforces #263 div2 解题报告

    比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注冊的时候非常想好好的做一下,可是网上喝了个小酒之后.也就迷迷糊糊地看了题目,做了几题.一觉醒来发现r ...

  9. codeforces #round363 div2.C-Vacations (DP)

    题目链接:http://codeforces.com/contest/699/problem/C dp[i][j]表示第i天做事情j所得到最小的假期,j=0,1,2. #include<bits ...

随机推荐

  1. 奇异值分解(SVD)小结

    SVD(奇异值分解)真的是一个神奇的东西,这里就写个小结. 其实原理并不是那么难理解. 它在数据去噪方面和降维上有特殊作用,也与PCA有很大的联系. 首先我们先回顾一下 EVD,特征值分解,可以对SV ...

  2. SPOJ Distinct Substrings(后缀数组求不同子串个数,好题)

    DISUBSTR - Distinct Substrings no tags  Given a string, we need to find the total number of its dist ...

  3. [Noip2004]虫食算 dfs

    搜索问题的关键:优秀的搜索策略以及行之有效的减枝 对于这道题我们阶乘搜肯定不行所以我们按位搜,我们对每一位的三个数进行赋值,然后判解. 对于此一类的搜索乘上一个几十的常数来减枝往往要比直接搜要快得多, ...

  4. 【NOIP模拟赛】beautiful 乱搞(平衡树)+ST

    biubiu~~~ 我用平衡树处理的这道题,然而这种方法还是要看评测姬..... 正解是乱搞....就是枚举每一位数作为中位数,比他小的看做-1比他大的看做1,那么我们从一开始就有了一个绵延的山,我们 ...

  5. Ajax缓存问题怎么解决?

    项目有时要用一些Ajax的效果,因为比较简单,也就没有去用什么Ajax.net之类的东西,手写代码也就实现了.第二天,有人向我报告错误:说是只有第一次读取的值正常,后面的值都不正常:我调试了一下 ,确 ...

  6. hdu 3473 (划分树)2

    Minimum Sum Time Limit: 16000/8000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  7. bzoj 4879 失控的数位板 4881 线段游戏 贪心,瞎搞

    [Lydsy1705月赛]失控的数位板 Time Limit: 30 Sec  Memory Limit: 256 MBSubmit: 148  Solved: 33[Submit][Status][ ...

  8. tomcat 配置文件中设置JAVA_HOME

    Tomcat默认情况下会用系统的环境变量中找到JAVA_HOME和JRE_HOME.但是有的时候我们需要不同版本的JDK共存. 可以在${TOMCAT_HOME}/bin/setclasspath.b ...

  9. [05] call by sharing || 共享参数

    转: https://segmentfault.com/a/1190000005177386 众所周知,JavaScript中参数是按值传递的.与访问变量不同,基本类型和引用类型的参数在传递时都如同变 ...

  10. DotNet 学习笔记 MVC模型

    Model Binding Below is a list of model binding attributes: •[BindRequired]: This attribute adds a mo ...