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 ...
随机推荐
- innodb_stats_on_metadata and slow queries on INFORMATION_SCHEMA
INFORMATION_SCHEMA is usually the place to go when you want to get facts about a system (how many ta ...
- VK Cup 2016 - Round 1 (Div. 2 Edition) A Bear and Reverse Radewoosh
A. Bear and Reverse Radewoosh time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- HDU1213:How Many Tables(并查集)
How Many Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- 怎么把linux的磁盘映射到windows上
步骤如下: 右击如下的computer: 然后选择:Map network drive... 然后在下图按图中所示操作: 最后成功如下图所示:
- centos6上使用fpm打python2.7 rpm包并兼容python2.6
centos6上使用fpm打python2.7 rpm包并兼容python2.6 作者 运维小兵_加油 关注 2016.09.22 00:28 字数 501 阅读 45评论 0喜欢 1 工作中我们常常 ...
- js 日期获去及格式化
原文地址:http://www.cnblogs.com/qinpengming/archive/2012/12/03/2800002.html Js获取当前日期时间及格式化操作 var myDate ...
- 通过7zip压缩备份文件bat
for %%X in (*log20*) do "c:\Program Files\7-Zip\7z.exe" a "backups\%%X.zip" &quo ...
- Ubuntu1604 install netease-cloud music
Two issue: 1. There is no voice on my computer, and the system was mute and cannot unmute. eric@E641 ...
- 教主泡嫦娥(RQNOJ 595)
题目描述 [问题背景] 2012年12月21日下午3点14分35秒,全世界各国的总统以及领导人都已经汇聚在中国的方舟上. 但也有很多百姓平民想搭乘方舟,毕竟他们不想就这么离开世界,所以他们决定要么登上 ...
- Spring securiuty 过滤器
1. HttpSessionContextIntegrationFilter 位于过滤器顶端,第一个起作用的过滤器. 用途一,在执行其他过滤器之前,率先判断用户的session中是否已经存在一个Sec ...