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 ...
随机推荐
- [转帖]Linux systemd 常用命令
Linux systemd 常用命令 https://www.cnblogs.com/tsdxdx/p/7288490.html systemctl hostnamectl timedatectl l ...
- shell备份脚本
#!/bin/bash #不存在的变量终止脚本执行 set -o nounset #执行出错终止脚本执行 set -o errexit #递归列出文件的绝对路径并执行压缩 delDir=`date - ...
- 数据库(mysql和oracle)
1. mysql索引: https://www.jikewenku.com/22030.html 2.
- 2-MySQL DBA笔记-MySQL安装部署和入门
第2章 MySQL安装部署和入门 第1章介绍了MySQL的一些基础知识,本章将为读者介绍MySQL的部署.安装及一些常用命令和参数的设置.2.1 如何选择MySQL版本 在选择MySQL的版本时,要根 ...
- docker启动mysql 自定义配置文件
命令行如下: docker run --name mysql56 -p : -v /home/mysql56/data:/var/lib/mysql -v /home/mysql56/conf:/et ...
- 设计模式 -- MVC
MVC 在Web中应用是常见的了,成为基础应用模式. 不好的用法是把业务写在C 中,M只是失血模型. 应该要重M 轻C,业务写在M中,但是这样有问题了.View 会引用Model,那么View会看到M ...
- 排查RabbitMQ安装错误
1.注册表中是否有 HKEY_LOCAL_MACHINE\SOFTWARE\Ericsson\Erlang\ErlSrv\1.1\RabbitMQ 此项.(须有) 2.安装目录是否存在中文.(不可有 ...
- JSON在JS中的应用
一. JSON在JS中的应用: 首先解释下JSON对象与普通js对象字面量定义时格式的区别: Js对象字面量定义格式: var person = { name:"Wede", ag ...
- get_object_or_404返回404(400)
get_object_or_404:第一个参数为queryset,第二个参数必须以关键字的形式传递,否则报错
- 【php设计模式】责任链模式
责任链模式为请求创建了一个接收者对象的链.这种模式给予请求的类型,对请求的发送者和接收者进行解耦.这种类型的设计模式属于行为型模式. 在这种模式中,通常每个接收者都包含对另一个接收者的引用.如果一个对 ...