证明在Tutorial的评论版里

  1. /*
  2. CodeForces 835D - Palindromic characteristics [ 分析,DP ] | Codeforces Round #427 (Div. 2)
  3. 题意:
  4. 定义 k 回文串满足:
  5. 1. 左右子串相等
  6. 2. 左右子串为k-1回文串
  7. 1 回文串 就是回文串
  8. 问你字符串s的子串的每阶回文子串的数目
  9. 分析:
  10. 研究一下可以发现 k 回文串的要求等价于
  11. 1. 本身是回文串
  12. 2. 左右子串是k-1回文串
  13. 然后可以dp了,还有一个结论是:
  14. 若一个串是 k 回文,那它一定是 k-1 回文
  15. 方便最后统计
  16. */
  17. #include <bits/stdc++.h>
  18. using namespace std;
  19. const int N = 5005;
  20. char s[N];
  21. int len;
  22. int dp[N][N], ans[N];
  23. void init()
  24. {
  25. int l;
  26. for (int i = 0; i < len; i++)
  27. {
  28. l = 0;
  29. while (i-l >= 0 && i+l < len && s[i-l] == s[i+l])
  30. {
  31. dp[i-l][i+l] = 1; ++ans[1];
  32. ++l;
  33. }
  34. l = 0;
  35. while (i-l >= 0 && i+l+1 < len && s[i-l] == s[i+l+1])
  36. {
  37. dp[i-l][i+l+1] = 1; ++ans[1];
  38. ++l;
  39. }
  40. }
  41. }
  42. void solve()
  43. {
  44. for (int k = 2; k <= len; k++)
  45. {
  46. for (int i = 0; i < len; i++)
  47. {
  48. int j = i+k-1;
  49. int mid = i+k/2-1;
  50. if (dp[i][mid] && dp[i][j])
  51. {
  52. dp[i][j] = max(dp[i][j], dp[i][mid]+1);
  53. ans[dp[i][j]]++;
  54. }
  55. }
  56. }
  57. }
  58. int main()
  59. {
  60. scanf("%s", s);
  61. len = strlen(s);
  62. init();
  63. solve();
  64. for (int i = len; i >= 2; i--)
  65. ans[i] += ans[i+1];
  66. for (int i = 1; i <= len; i++)
  67. printf("%d ", ans[i]);
  68. puts("");
  69. }

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. [转帖]Linux systemd 常用命令

    Linux systemd 常用命令 https://www.cnblogs.com/tsdxdx/p/7288490.html systemctl hostnamectl timedatectl l ...

  2. shell备份脚本

    #!/bin/bash #不存在的变量终止脚本执行 set -o nounset #执行出错终止脚本执行 set -o errexit #递归列出文件的绝对路径并执行压缩 delDir=`date - ...

  3. 数据库(mysql和oracle)

    1.   mysql索引:    https://www.jikewenku.com/22030.html 2.

  4. 2-MySQL DBA笔记-MySQL安装部署和入门

    第2章 MySQL安装部署和入门 第1章介绍了MySQL的一些基础知识,本章将为读者介绍MySQL的部署.安装及一些常用命令和参数的设置.2.1 如何选择MySQL版本 在选择MySQL的版本时,要根 ...

  5. docker启动mysql 自定义配置文件

    命令行如下: docker run --name mysql56 -p : -v /home/mysql56/data:/var/lib/mysql -v /home/mysql56/conf:/et ...

  6. 设计模式 -- MVC

    MVC 在Web中应用是常见的了,成为基础应用模式. 不好的用法是把业务写在C 中,M只是失血模型. 应该要重M 轻C,业务写在M中,但是这样有问题了.View 会引用Model,那么View会看到M ...

  7. 排查RabbitMQ安装错误

    1.注册表中是否有  HKEY_LOCAL_MACHINE\SOFTWARE\Ericsson\Erlang\ErlSrv\1.1\RabbitMQ 此项.(须有) 2.安装目录是否存在中文.(不可有 ...

  8. JSON在JS中的应用

    一. JSON在JS中的应用: 首先解释下JSON对象与普通js对象字面量定义时格式的区别: Js对象字面量定义格式: var person = { name:"Wede", ag ...

  9. get_object_or_404返回404(400)

    get_object_or_404:第一个参数为queryset,第二个参数必须以关键字的形式传递,否则报错

  10. 【php设计模式】责任链模式

    责任链模式为请求创建了一个接收者对象的链.这种模式给予请求的类型,对请求的发送者和接收者进行解耦.这种类型的设计模式属于行为型模式. 在这种模式中,通常每个接收者都包含对另一个接收者的引用.如果一个对 ...