【CF】7 Beta Round D. Palindrome Degree

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 ;
}
上一篇:Android测试(二)——drozer使用


下一篇:POJ 2374 线段树建图+Dijkstra