Codeforces Round #427 (Div. 2) D - Palindromic characteristics
本题是个简单的区间dp
dp[l][r]=dp[l][mid]+1
最近都没时间做题了,被我妈强制喊回去,然后颓废了10天(回家也没发控制住自己= = 我的锅),计划都打乱了,本来还报名了百度之星,然后没时间参加
#include<cmath>
#include<map>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 5e3+5;
#define MS(x,y) memset(x,y,sizeof(x))
#define MP(x, y) make_pair(x, y)
const int INF = 0x3f3f3f3f;
char s[N];
int dp[N][N];
int ans[N];
int main() {
while(~scanf("%s", s+1)) {
int n = strlen(s + 1);
memset(dp, 0, sizeof(dp));
memset(ans, 0, sizeof(ans));
for(int i = 1; i <= n; ++i) {
for(int j = 1; j+i-1 <= n; ++j) {
int l = j; int r = j+i-1;
if(l == r) dp[l][r] = 1;
else if(s[l] == s[r]) {
if(dp[l+1][r-1]) {
int tt = (l+r-1) / 2;
dp[l][r] = dp[l][tt] + 1;
} else if(l == r - 1) dp[l][r] = 2;
}
}
// for(int j = 1; j+i-1 <= n; ++j) printf("%d->%d: %d ", j,j+i-1,dp[j][j+i-1]); printf("\n");
}
for(int i = 1; i <= n; ++i) {
for(int j = i; j <= n; ++j) {
ans[dp[i][j]] ++;
}
}
for(int i = n; i >= 1; --i) {
ans[i] += ans[i + 1];
}
for(int i = 1; i <= n; ++i) {
if(i != 1) printf(" ");
printf("%d", ans[i]);
}
printf("\n");
}
return 0;
}