Codeforces Round #427 (Div. 2) D dp
3 seconds
256 megabytes
standard input
standard output
Palindromic characteristics of string s with length |s| is a sequence of |s| integers, where k-th number is the total number of non-empty substrings of s which are k-palindromes.
A string is 1-palindrome if and only if it reads the same backward as forward.
A string is k-palindrome (k > 1) if and only if:
- Its left half equals to its right half.
- Its left and right halfs are non-empty (k - 1)-palindromes.
The left half of string t is its prefix of length ⌊|t| / 2⌋, and right half — the suffix of the same length. ⌊|t| / 2⌋ denotes the length of string t divided by 2, rounded down.
Note that each substring is counted as many times as it appears in the string. For example, in the string "aaa" the substring "a" appears 3 times.
The first line contains the string s (1 ≤ |s| ≤ 5000) consisting of lowercase English letters.
Print |s| integers — palindromic characteristics of string s.
abba
6 1 0 0
abacaba
12 4 1 0 0 0 0
In the first example 1-palindromes are substring «a», «b», «b», «a», «bb», «abba», the substring «bb» is 2-palindrome. There are no 3- and 4-palindromes here.
题意:给你一个字符串 问1~len阶的子串的个数 一个回文串可以称为一阶子串 k阶子串的左右两边为k-1阶子串
题解:dp[i][j]表示原字符串中i~j为dp[i][j]阶
#pragma comment(linker, "/STACK:102400000,102400000")
#include <bits/stdc++.h>
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <string>
#include <complex>
#define ll __int64
#define mod 1000000007
using namespace std;
char s[];
int re[];
int dp[][];
int main()
{
scanf("%s",s+);
int len=strlen(s+);
for(int i=;i<=len;i++){
dp[i][i]=;
re[]++;
if(i!=len&&s[i]==s[i+]){
dp[i][i+]=;
re[]++;
re[]++;
}
}
for(int i=;i<=len;i++)//枚举字串的长度
for(int j=;j+i-<=len;j++){
if(dp[j+][j+i-]&&s[j]==s[i+j-]){
dp[j][j+i-]=dp[j][j+i/-]+;
for(int k=;k<=dp[j][i+j-];k++) re[k]++;
}
}
for(int i=;i<=len;i++)
printf("%d ",re[i]);
return ;
}
Codeforces Round #427 (Div. 2) D dp的更多相关文章
- CodeForces 835D - Palindromic characteristics | Codeforces Round #427 (Div. 2)
证明在Tutorial的评论版里 /* CodeForces 835D - Palindromic characteristics [ 分析,DP ] | Codeforces Round #427 ...
- CodeForces 835C - Star sky | Codeforces Round #427 (Div. 2)
s <= c是最骚的,数组在那一维开了10,第八组样例直接爆了- - /* CodeForces 835C - Star sky [ 前缀和,容斥 ] | Codeforces Round #4 ...
- 严格递增类的dp Codeforces Round #371 (Div. 1) C dp
http://codeforces.com/contest/713 题目大意:给你一个长度为n的数组,每次有+1和-1操作,在该操作下把该数组变成严格递增所需要的最小修改值是多少 思路:遇到这类题型, ...
- 很好的一个dp题目 Codeforces Round #326 (Div. 2) D dp
http://codeforces.com/contest/588/problem/D 感觉吧,这道题让我做,我应该是不会做的... 题目大意:给出n,L,K.表示数组的长度为n,数组b的长度为L,定 ...
- Codeforces Round #548 (Div. 2) C dp or 排列组合
https://codeforces.com/contest/1139/problem/C 题意 一颗有n个点的树,需要挑选出k个点组成序列(可重复),按照序列的顺序遍历树,假如经过黑色的边,那么这个 ...
- Codeforces Round #536 (Div. 2) E dp + set
https://codeforces.com/contest/1106/problem/E 题意 一共有k个红包,每个红包在\([s_i,t_i]\)时间可以领取,假如领取了第i个红包,那么在\(d_ ...
- Codeforces Round #541 (Div. 2) G dp + 思维 + 单调栈 or 链表 (连锁反应)
https://codeforces.com/contest/1131/problem/G 题意 给你一排m个的骨牌(m<=1e7),每块之间相距1,每块高h[i],推倒代价c[i],假如\(a ...
- Codeforces Round #543 (Div. 2) F dp + 二分 + 字符串哈希
https://codeforces.com/contest/1121/problem/F 题意 给你一个有n(<=5000)个字符的串,有两种压缩字符的方法: 1. 压缩单一字符,代价为a 2 ...
- Codeforces Round #427 (Div. 2)—A,B,C,D题
A. Key races 题目链接:http://codeforces.com/contest/835/problem/A 题目意思:两个比赛打字,每个人有两个参数v和t,v秒表示他打每个字需要多久时 ...
随机推荐
- Cesium开发添加entity无法显示
无代码报错,js查询entity数量发现确实添加进去了.但是在底图上就是不显示. 有可能是跨域产生的问题.打开开发者工具Console栏.查看是不是存在跨域错误. 解决跨域后entity正常加载.
- 深圳第XX天
今天早晨,面了一家小公司.先说结果吧,面过了.但是,总感觉太假了.面试中很多问题都没有回答上来.然后老板看了一下简历,问:期薪资多少?我想了想,说7000.啊,要不留下来看看?我答应了.不到十分钟,就 ...
- Hyperledger中的共识机制
Hyperledger Consensus 共识过程 Hyperlydger中建立共识的过程由以下两个独立的过程构成: Ordering of transactions (交易排序) Validati ...
- 7. I/O复用
一.I/O复用的特点 能同时监听多个文件描述符 自身是阻塞的 当多个文件描述符同时就绪时,如果不采取额外的措施,程序就只能按顺序依次处理其中的每一个文件描述符 由于其第三个特点,所以服务器程序看起来仍 ...
- Scrum立会报告+燃尽图(Beta阶段第二周第一次)
此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2409 项目地址:https://coding.net/u/wuyy694 ...
- snprintf vs sprintf
#include <stdio.h> int printf(const char *format, ...); int fprintf(FILE *stream, const char * ...
- MySql 8 命令
1-创建用户 create user 用户名@'%' identified by '密码'; create user 用户名@'localhost' identified by '密码'; 2-授 ...
- java沙盒入门
程序员写一个Java程序,默认的情况下你可以访问任意的机器资源,比如读取,删除一些文件或者网络操作等.当你把程序部署到正式的服务器上,系统管理员要为服务器的安全承担责任,那么他可能不敢确定你的程序会不 ...
- 软工网络15团队作业4-DAY5
每日例会 昨天的工作. 张陈东芳:界面排版优化 吴敏烽:界面排版优化 周汉麟:继续根据商品编号来获取商品资料方法调试 林振斌:继续输出最近浏览记录的方法调试 李智:界面排版优化 全体人员:界面优化,初 ...
- HDU 2162 Add ‘em
http://acm.hdu.edu.cn/showproblem.php?pid=2162 Problem Description Write a program to determine the ...