D. Palindromic characteristics 解析(DP)
Codeforce 835 D. Palindromic characteristics 解析(DP)
今天我們來看看CF835D
題目連結
題目
略,請看原題
前言
想不到這種狀態...

想法
\(dp[L][R]\)代表區間\([L,R)\)是\(dp[L][R]-palindrome\)
從長度為\(2\)的區段慢慢算到長度為\(n\)的區段。
如果\(s[L]==s[R-1]\),那麼只要\([L+1,R-1)\)是回文,這整段就會是回文,因此\(dp[L][R]=dp[L][M]+1\),其中\(M=\lfloor\frac{L+R}{2}\rfloor\)
程式碼:
const int _n=5010;
int t,n,dp[_n][_n],ans[_n],suf[_n];
string s;
main(void) {ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>s;n=s.length();rep(i,0,n)dp[i][i]=0,dp[i][i+1]=1;
rep(j,2,n+1)rep(i,0,n+1-j){
int L=i,R=L+j,m=(L+R)/2;
if(s[L]==s[R-1] and (dp[L+1][R-1] or L+1==R-1))dp[L][R]=dp[L][m]+1;
}rep(j,1,n+1)rep(i,0,n+1-j)ans[dp[i][i+j]]++;
suf[n]=ans[n];per(i,1,n)suf[i]=suf[i+1]+ans[i];
rep(i,1,n+1)cout<<suf[i]<<' ';
return 0;
}
標頭、模板請點Submission看
Submission
D. Palindromic characteristics 解析(DP)的更多相关文章
- CodeForces 835D - Palindromic characteristics | Codeforces Round #427 (Div. 2)
证明在Tutorial的评论版里 /* CodeForces 835D - Palindromic characteristics [ 分析,DP ] | Codeforces Round #427 ...
- 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) Problem D Palindromic characteristics (Codeforces 835D) - 记忆化搜索
Palindromic characteristics of string s with length |s| is a sequence of |s| integers, where k-th nu ...
- 【CF835D】Palindromic characteristics 加强版 解题报告
[CF835D]Palindromic characteristics 加强版 Description 给你一个串,让你求出\(k\)阶回文子串有多少个.\(k\)从\(1\)到\(n\). \(k\ ...
- D. Palindromic characteristics
time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standa ...
- 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 ...
- C1. Pokémon Army (easy version) 解析(DP)
Codeforce 1420 C1. Pokémon Army (easy version) 解析(DP) 今天我們來看看CF1420C1 題目連結 題目 對於一個數列\(a\),選若干個數字,求al ...
- D. Yet Another Problem On a Subsequence 解析(DP)
Codeforce 1000 D. Yet Another Problem On a Subsequence 解析(DP) 今天我們來看看CF1000D 題目連結 題目 略,請直接看原題 前言 這題提 ...
- [加强版] Codeforces 835D Palindromic characteristics (回文自动机、DP)
题目链接: https://codeforces.com/contest/835/problem/D 题意: 一个回文串是\(1\)-回文的,如果一个回文串的左半部分和右半部分一样且都是\(k\)-回 ...
随机推荐
- 阅读源码的利器——Intellij-IDEA-Replace-in-Path-使用技巧
前言 讲讲宇宙排名第二的开发工具-–IDEA的使用技巧. 搜索/替换 技巧 阅读源码的利器 1.Match case: 如果勾选该按钮,搜索时将区分大小写字母. 2.Preserve case ...
- Oracle学习(十三)优化专题
一.查询频繁,数据量大 索引 使用时机:表中经常查询的字段可以考虑添加索引. 联合索引:若能确认多个条件会同时使用时,可以将这几个条件作为联合索引. 单列索引:若条件查询时,这几个条件不是同时用到的话 ...
- C++获取运行程序当前目录
1 HMODULE GetSelfModuleHandle() 2 { 3 MEMORY_BASIC_INFORMATION mbi; 4 return ((::VirtualQuery(GetSel ...
- Hadoop框架:集群模式下分布式环境搭建
本文源码:GitHub·点这里 || GitEE·点这里 一.基础环境配置 1.三台服务 准备三台Centos7服务,基础环境从伪分布式环境克隆过来. 133 hop01,134 hop02,136 ...
- sping ioc 源码分析(一)-- register(componentClasses) 方法
一.测试环境的搭建: public class Apple { } @Component public class MyComponet { } public class MyCondition im ...
- win10 配置 maven | 下载与配置
<!-- 阿里云仓库 --> <mirrors> <mirror> <id>nexus-aliyun</id> <mirrorOf&g ...
- Centos-当前登录用户信息- w who
w who 显示当前登录系统的用户,但w显示的更为详细 who 相关参数 # 默认输出 用户名.登录终端.登录时间 -a 列出所有信息 -b 系统最近启动日期 -m 当前终端信息,相当于 w ...
- Archive: ****** End-of-central-directory signature not found. Either this file is not a zipfile, or it constitutes
Archive: demoApi.zip End-of-central-directory signature not found. Either this file is not a z ...
- 如何用5000行JS撸一个关系型数据库
首先声明,我不是标题党,我真的是用5000行左右的JS实现了一个轻量级的关系型数据库JSDB,核心是一个SQL编译器,支持增删改查. 源代码放到github上了:https://github.com/ ...
- DOS批处理中%cd%与%~dp0的区别详解
转载:https://www.jb51.net/article/105325.htm DOS批处理中%cd%与%~dp0的区别详解 Windows下批处理中%cd%和%~dp0都能用来表示当前 ...