835D:http://codeforces.com/problemset/problem/835/D
emmmm不太会,附大佬代码
#include<iostream> #include<algorithm> #include<string.h> using namespace std; int len,ans; char t[5005]; int dp[5005][5005]; int num[5005]; int main() { while (cin>>t) { memset(dp, 0, sizeof(dp)); memset(num, 0, sizeof(num)); len = strlen(t); for (int i = 0; i < len; i++) { dp[i][i] = 1; num[1]++; if (t[i] == t[i + 1] && i < len-1) { dp[i][i + 1] = 2; num[2]++; num[1]++; } } for (int i = 1; i<=len; i++) for (int j = 0; j + i + 1 < len; j++) { if (t[j] == t[j + i + 1] && dp[j + 1][j + i]) dp[j][j + i + 1] = dp[j][j + i / 2] + 1; for (int k = 1; k <= dp[j][j + i + 1]; k++) num[k]++; } for (int i = 1; i <= len; i++) { cout << num[i]; i != len ? cout << " " : cout << endl; } } return 0; }