【Link】:http://codeforces.com/contest/835/problem/D

【Description】



给你一个字符串;

让你在其中找到1..k阶的回文子串;

并统计它们的数量

如果一个字符串是一个回文串,则它可以是1阶子串;

k阶字符串,要求它的左边和右边都是k-1阶子串;

【Solution】



bo[i][j]表示i..j这一段是否为回文;

可以用O(n2)的复杂度处理出整个bo数组;

然后O(n2)枚举每一段区间;

算出这个区间的字符串最大可以是一个几阶字符串记为k;

ans[k]++;

如何算?

递归!

void getk(int l,int r)

如果l..r这一段不是回文,则直接返回0;

可以认为他是”0”阶子串;

如果l..r这一段是回文;

那么就只要在l..mid和mid..r这两段中选一段;

递归求它的字符串阶数+1就好了;

不用两个都算!

则这里复杂度为O(log2n)

总的复杂度为O(n2log2n)

最后;

阶数为i的字符串也被认为是阶数为1..i的字符串;

所以

for (int i = n-1;i >= 1;i–)

ans[i]+=ans[i+1];



【NumberOf WA】



2



【Reviw】



我一开始,想的是,从低阶的字符串推出高阶的字符串

没有考虑到,这样增长得是很快的;

竟然没有想到逆向..



【Code】

#include <bits/stdc++.h>
using namespace std; const int N = 5e3; char s[N+10];
int n,bo[N+10][N+10],ans[N+10];
//int dp[N+10][N+10]; int getk(int l,int r){
if (!bo[l][r]) return 0;
if (l==r) return 1;
if (l+1==r) return 2;
int len = (r-l+1)/2;
int L = l,R = r;
return getk(L,L+len-1)+1;
} int main(){
// memset(dp,255,sizeof dp);
scanf("%s",s+1);
n = strlen(s+1); for (int i = 1;i <= n;i++){
bo[i][i] = 1;
if (i+1 <= n && s[i]==s[i+1]) bo[i][i+1] = 1;
}
for (int i = 3;i <= n;i++){
for (int j = 1;j <= n;j++){
int r = j + i - 1;
if (r > n) break;
if (bo[j+1][r-1] && s[j]==s[r]) bo[j][r] = 1;
}
} for (int i = 1;i <= n;i++)
for (int j = i;j <= n;j++){
ans[getk(i,j)]++;
}
for (int i = n-1;i >= 1;i--)
ans[i]+=ans[i+1];
for (int i = 1;i <= n;i++)
printf("%d ",ans[i]);
return 0;
}

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

  1. 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 ...

  2. 【Codeforces Round #427 (Div. 2) A】Key races

    [Link]:http://codeforces.com/contest/835/problem/A [Description] [Solution] 傻逼题. [NumberOf WA] [Revi ...

  3. 【Codeforces Round #427 (Div. 2) B】The number on the board

    [Link]:http://codeforces.com/contest/835 [Description] 原本有一个数字x,它的各个数码的和原本是>=k的; 现在这个数字x,在不改变位数的情 ...

  4. 【Codeforces Round #427 (Div. 2) C】Star sky

    [Link]:http://codeforces.com/contest/835/problem/C [Description] 给你n个星星的坐标(xi,yi); 第i个星星在第t秒,闪烁值变为(s ...

  5. 【Codeforces Round #432 (Div. 1) B】Arpa and a list of numbers

    [链接]h在这里写链接 [题意] 定义bad list是一个非空的.最大公约数为1的序列.给定一个序列,有两种操作:花费x将一个元素删除.花费y将一个元素加1,问你将这个序列变为good list所需 ...

  6. 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes

    [题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...

  7. 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees

    [题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...

  8. 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory

    [题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...

  9. 【Codeforces Round #423 (Div. 2) C】String Reconstruction

    [Link]:http://codeforces.com/contest/828/problem/C [Description] 让你猜一个字符串原来是什么; 你知道这个字符串的n个子串; 且知道第i ...

随机推荐

  1. [洛谷P1343]地震逃生

    题目大意:有n个点m条单向边,每条边有一个容量.现有x人要分批从1走到n,问每批最多能走多少人,分几批运完(或输出无法运完). 解题思路:一看就是网络流的题目.每批最多能走多少人,即最大流.分几批运完 ...

  2. 在VPS上用Outline Manager 建立*** 增强版服务器

    在VPS上用Outline Manager 建立*** 增强版服务器 原文 https://free.com.tw/google-outline/ Outline 是Google Jigsaw的一款开 ...

  3. 21.MFC进制转换工具

    相关代码:链接:https://pan.baidu.com/s/1pKVVUZL 密码:e3vf #include <stdlib.h> #include <stdio.h> ...

  4. sql阻塞进程查询

    select A.SPID as 被阻塞进程,a.CMD AS 正在执行的操作,b.spid AS 阻塞进程号,b.cmd AS 阻塞进程正在执行的操作 from master..sysprocess ...

  5. BZOJ 1112 线段树

    思路: 权值线段树 (找中位数用的) 记录下出现的次数和sum 一定要注意 有可能中位数的值有许多数 这怎么办呢 (离散化以后不去重就行了嘛--.) (为什么他们想得那么麻烦) //By Sirius ...

  6. vue中剖析中的一些方法

    1 判断属性 71 -81 var hasOwnProperty = Object.prototype.hasOwnProperty; /** * Check whether the object h ...

  7. 图论:Tarjan算法

    在有向图中,若两点至少包含一条路径可以到达,则称两个顶点强连通,若任意两个顶点皆如此,则称此图为强联通图.非强连通图有向图的极大强连通子图,称为强连通分量(strongly connected com ...

  8. 如何利用Python词云和wordart可视化工具对朋友圈数据进行可视化展示

    大前天我们通过Python网络爬虫对朋友圈的数据进行了抓取,感兴趣的朋友可以点击进行查看,如何利用Python网络爬虫抓取微信朋友圈的动态(上)和如何利用Python网络爬虫爬取微信朋友圈动态——附代 ...

  9. Vuejs2.0构建一个彩票查询WebAPP(1)

    说明:本人也是刚接触VUE.js,作为一个学习笔记,旨在与初学者共同学习.其中编程语法错误或者写作水平刺眼,还望轻喷. 使用工具:Visual Studio Code.技术栈为vue2+vuex+ax ...

  10. vue-cli · Failed to download repo vuejs-templates/webpack-simple: tunneling socket could not be established, cause=connect ECONNREFUSED 127.0.0.1:8086 && vue init webpack-simple xxx

    vue init webpack-simple mywork报错如下: vue-cli · Failed to download repo vuejs-templates/webpack-simple ...