manacher+dp.其实理解manacher就可以解了,大水题,dp就是dp[i]=dp[i>>1]+1如何满足k-palindrome条件。

 /* 7D */
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <deque>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <functional>
#include <iterator>
#include <iomanip>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,1024000") #define sti set<int>
#define stpii set<pair<int, int> >
#define mpii map<int,int>
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define rep(i, a, n) for (int i=a;i<n;++i)
#define per(i, a, n) for (int i=n-1;i>=a;--i)
#define clr clear
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1 const int maxn = 5e6+;
int dp[maxn];
int Len[maxn*];
char s[maxn];
char d[maxn*]; void init() {
int slen = strlen(s);
int j = ; d[j++] = '$';
d[j++] = '#';
rep(i, , slen) {
d[j++] = s[i];
d[j++] = '#';
}
} void manacher() {
int dlen = strlen(d);
int p = , p0 = ; rep(i, , dlen) {
if (p > i)
Len[i] = min(p-i, Len[*p0-i]);
else
Len[i] = ;
while (d[i+Len[i]] == d[i-Len[i]])
++Len[i];
if (i + Len[i] > p) {
p = i + Len[i];
p0 = i;
}
}
} void solve() {
init();
manacher(); int slen = strlen(s);
int ans = ; dp[] = ;
rep(i, , slen+) {
if (Len[i+] >= i+) {
dp[i] = dp[i>>] + ;
}
ans += dp[i];
} printf("%d\n", ans);
} int main() {
ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif scanf("%s", s);
solve(); #ifndef ONLINE_JUDGE
printf("time = %d.\n", (int)clock());
#endif return ;
}

【CF】7 Beta Round D. Palindrome Degree的更多相关文章

  1. 【计算几何】 Codeforces Beta Round #67 (Div. 2) E. Ship's Shortest Path

    读懂题意其实是模板题.就是细节略多. #include<cstdio> #include<cmath> #include<algorithm> using name ...

  2. Codeforces Beta Round #7--D. Palindrome Degree(Manacer)

    题目:http://blog.csdn.net/winddreams/article/details/44218961 求出每一个点为中心的最长字符串,推断该串是不是从开头的回文串. #include ...

  3. 【BZOJ1662】[Usaco2006 Nov]Round Numbers 圆环数 数位DP

    [BZOJ1662][Usaco2006 Nov]Round Numbers 圆环数 Description 正如你所知,奶牛们没有手指以至于不能玩"石头剪刀布"来任意地决定例如谁 ...

  4. 【概率论】5-8:Beta分布(The Beta Distributions)

    title: [概率论]5-8:Beta分布(The Beta Distributions) categories: - Mathematic - Probability keywords: - Th ...

  5. 【题解】Comet OJ Round 70 简要题解

    [题解]Comet OJ Round 70 简要题解 A 将放在地上的书按照从小到大排序后,问题的本质就变成了合并两个序列使得字典序最小.可以直接模拟归并排序.直接用循环和std::merge实现这个 ...

  6. 【扫描线】Educational Codeforces Round 4 D. The Union of k-Segments

    http://codeforces.com/contest/612/problem/D [题解] http://blog.csdn.net/strokess/article/details/52248 ...

  7. 【LOJ511】[LibreOJ NOI Round #1]验题(动态DP)

    我这道题写了整!整!三!天! 我要一定要写这篇博客来表达我复!杂!的!心!情! 题目 LOJ511 官方题解(这个题解似乎不是很详细,我膜 std 才看懂的) 调这道题验证了我校某人的一句话:调题是一 ...

  8. 【测试】trunc和round的区别

    trunc是截断:round是四舍五入:下面通过一个例子具体看一下trunc和round的不同 SQL),trunc() from dual; TRUNC() TRUNC() ------------ ...

  9. 【Codeforces752D】Santa Claus and a Palindrome [STL]

    Santa Claus and a Palindrome Time Limit: 20 Sec  Memory Limit: 512 MB Description 有k个串,串长都是n,每个串有一个a ...

随机推荐

  1. ScriptManager的用法

    资料中如实是说:       1, ScriptManager(脚本控制器)是asp.net ajax存在的基础. 2, 一个页面只允许有一个ScriptManager,并且放在其他ajax控件的前面 ...

  2. SSIS结合BCP及SQL Server作业实现定时将数据导出打包实现数据同步

    首先这个流程要实现的功能大致是: 有两台服务器,一台是对外网开发的,一台是内网的.那么很明显数据交互都是外网服务器在做,而这个流程要做的就是要将外网上面的数据定时同步到内网中. 我们依对其中某张表的操 ...

  3. 什么是SysWow64

    转自 什么是SysWow64 Wow!什么是Wow64 64位的Windows并不是简单地把所有东西都编译成64位就万事大吉的.关于64位的CPU应该做成什么样子,Intel和AMD曾有各自的打算.A ...

  4. LiangNa Resum

    LiangNa AnShan Street, YangPu, NY @.com OBJECTIVE: Seeking a position to contribute my skills and ed ...

  5. mysql 直接从date 文件夹备份表,还原数据库之后提示 table doesn`t exist的原因和解决方法

    补充:正常情况下,建议数据库备份最好用工具进行备份,通过拷贝数据库表进行数据迁移,不同的环境会出现各种不同的意外问题. 背景:今天在整理一个网站的时候,操作系统由于系统自动更新导致一直出现系统蓝屏死机 ...

  6. 第17条:实现description方法

    自定义类需要自己覆写description方法,否则打印信息时就会调用NSObject类所实现的默认方法.(如果不覆写,只会输出类名和对象的内存地址的信息,这只有在判断两个指针是否指向同一对象时才有用 ...

  7. iOS--NSNetService和NSNetServiceBrowser(Bonjour网络编程)

    Cocoa 网络框架: Cocoa 网络框架有三层,最底层的是基于 BSD socket库,然后是 Cocoa 中基于 C 的 CFNetwork,最上面一层是 Cocoa 中 Bonjour.通常我 ...

  8. weewwe

    http://blog.csdn.net/u013073524/article/details/25912891

  9. java web 文件上传下载

    文件上传下载案例: 首先是此案例工程的目录结构:

  10. 【转】PHP网站常见安全漏洞,及相应防范措施总结

    ---恢复内容开始--- 目前,基于PHP的网站开发已经成为目前网站开发的主流,本文笔者重点从PHP网站攻击与安全防范方面进行探究,旨在减少网站漏洞,希望对大家有所帮助! 一.常见PHP网站安全漏洞 ...