本题是个简单的区间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;
}

Codeforces Round #427 (Div. 2) D - Palindromic characteristics的更多相关文章

  1. CodeForces 835D - Palindromic characteristics | Codeforces Round #427 (Div. 2)

    证明在Tutorial的评论版里 /* CodeForces 835D - Palindromic characteristics [ 分析,DP ] | Codeforces Round #427 ...

  2. CodeForces 835C - Star sky | Codeforces Round #427 (Div. 2)

    s <= c是最骚的,数组在那一维开了10,第八组样例直接爆了- - /* CodeForces 835C - Star sky [ 前缀和,容斥 ] | Codeforces Round #4 ...

  3. Codeforces Round #427 (Div. 2) Problem D Palindromic characteristics (Codeforces 835D) - 记忆化搜索

    Palindromic characteristics of string s with length |s| is a sequence of |s| integers, where k-th nu ...

  4. Codeforces Round #427 (Div. 2) [ C. Star sky ] [ D. Palindromic characteristics ] [ E. The penguin's game ]

    本来准备好好打一场的,然而无奈腹痛只能带星号参加 (我才不是怕被打爆呢!) PROBLEM C - Star sky 题 OvO http://codeforces.com/contest/835/p ...

  5. Codeforces Round #427 (Div. 2)—A,B,C,D题

    A. Key races 题目链接:http://codeforces.com/contest/835/problem/A 题目意思:两个比赛打字,每个人有两个参数v和t,v秒表示他打每个字需要多久时 ...

  6. Codeforces Round #427 (Div. 2) D dp

    D. Palindromic characteristics time limit per test 3 seconds memory limit per test 256 megabytes inp ...

  7. 【Codeforces Round #427 (Div. 2) D】Palindromic characteristics

    [Link]:http://codeforces.com/contest/835/problem/D [Description] 给你一个字符串; 让你在其中找到1..k阶的回文子串; 并统计它们的数 ...

  8. Codeforces Round #540 (Div. 3) C. Palindromic Matrix 【暴力】

    任意门:http://codeforces.com/contest/1118/problem/C C. Palindromic Matrix time limit per test 2 seconds ...

  9. Codeforces Round #540 (Div. 3)--1118C - Palindromic Matrix

    https://codeforces.com/contest/1118/problem/C 在查找元素的时候,必须按4,2,1的顺序进行.因为,如果先找1,可能就把原来的4拆散了,然后再找4,就找不到 ...

随机推荐

  1. Linux中的Buffer 与 Cache

    A buffer is something that has yet to be "written" to disk.       A cache is something tha ...

  2. Oracle常见授权与回收权限——grant和revoke

    1.GRANT 赋于权限常用的系统权限集合有以下三个:CONNECT(基本的连接), RESOURCE(程序开发), DBA(数据库管理) 常用的数据对象权限有以下五个:ALL ON 数据对象名, S ...

  3. bind,apply,call区别总结

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  4. 【算法】哈希表的诞生(Java)

    参考资料 <算法(java)>                           — — Robert Sedgewick, Kevin Wayne <数据结构>       ...

  5. php环境搭建和第一个php程序

    一.开发环境搭建 因为是初学,使用的还是非常经典的组合appserv+dreamweaver cs6; 1.1   appserv安装 appserv的安装还是非常简单的,直接双击可执行程序appse ...

  6. 时间序列数据库rrd启动

    然后执行启动定时任务目录:etc/crontab SHELL=/bin/bashPATH=/sbin:/bin:/usr/sbin:/usr/binMAILTO=rootHOME=/ # For de ...

  7. scala学习

    前言 Bruce Eckel在吐槽Java,一是本身的不合理的地方太多,二是Oracle的商业目的导致Java的发布显得有点仓促,许多地方存在不合理,这样便加速了Java的不合理.此外,Bruce提到 ...

  8. Linux 快速执行历史命令,用 !编号

    例如: history | grep mysql 使用 !914 可以快速执行上述命令:

  9. 洛谷P3369 【模板】普通平衡树(Treap/SBT)

    洛谷P3369 [模板]普通平衡树(Treap/SBT) 平衡树,一种其妙的数据结构 题目传送门 题目描述 您需要写一种数据结构(可参考题目标题),来维护一些数,其中需要提供以下操作: 插入x数 删除 ...

  10. .NET 设计模式的六大原则理论知识

    1. 单一职责原则(SRP)(Single Responsibility Principle)2. 里氏替换原则(LSP)(Liskov Substitution Principle)3. 依赖倒置原 ...