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;
}
Codeforces Round #427 (Div. 2) D - Palindromic characteristics的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #427 (Div. 2)—A,B,C,D题
A. Key races 题目链接:http://codeforces.com/contest/835/problem/A 题目意思:两个比赛打字,每个人有两个参数v和t,v秒表示他打每个字需要多久时 ...
- Codeforces Round #427 (Div. 2) D dp
D. Palindromic characteristics time limit per test 3 seconds memory limit per test 256 megabytes inp ...
- 【Codeforces Round #427 (Div. 2) D】Palindromic characteristics
[Link]:http://codeforces.com/contest/835/problem/D [Description] 给你一个字符串; 让你在其中找到1..k阶的回文子串; 并统计它们的数 ...
- Codeforces Round #540 (Div. 3) C. Palindromic Matrix 【暴力】
任意门:http://codeforces.com/contest/1118/problem/C C. Palindromic Matrix time limit per test 2 seconds ...
- Codeforces Round #540 (Div. 3)--1118C - Palindromic Matrix
https://codeforces.com/contest/1118/problem/C 在查找元素的时候,必须按4,2,1的顺序进行.因为,如果先找1,可能就把原来的4拆散了,然后再找4,就找不到 ...
随机推荐
- elasticsearch的percolator操作
es的普通查询是通过某些条件来查询满足的文档,percolator则不同,先是注册一些条件,然后查询一条文档是否满足其中的某些条件. es的percolator特性在数据分类.数据路由.事件监控和预警 ...
- Timer类的schedule和scheduleAtFixedRate 简单应用
Timer类可以用作定时任务,主要的方法有schedule和scheduleAtFixedRate. schedule(TimerTask task, Date time) 安排在指定的时间执行指定的 ...
- Python基础篇(九)
Key Words: 文件迭代器,标准输入,GUI工具包,数据库操作SQLlite,socket编程 文件迭代器 >>> f= open("some.txt",& ...
- BZOJ 3028: 食物 [生成函数 隔板法 | 广义二项式定理]
3028: 食物 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 497 Solved: 331[Submit][Status][Discuss] De ...
- Flask 开发| Flaskr 开发内容总结
Flaskr 开发说明 官方文档 http://flask.pocoo.org/docs/0.12/tutorial/ 演示网站 http://flaskr.it592.com/ 涉及到的内容: 连接 ...
- 前端js代码优化
今天给大家分享下js代码优化的相关技巧. 1.使用"+"转换为数值 我们平时开发过程中需要将数字字符串创转为number类型,大多数都会用JavaScript parseI ...
- [Python Study Notes] 变量/编码/注释
Ps:我这里选择的IDE为pycharm,个人感觉还是比较好用的. 1.变量 声明变量/赋值变量 #_*_ coding:utf-8 _*_ # author = "liu" ab ...
- ajaxfileupload批量上传文件+图片尺寸限制
1.首先展示ajaxfileupload代码,在这里修改为批量上传 //ajaxfileupload不展示全部代码,这是修改前与修改后代码对比,目的是上传多个文件 createUploadForm: ...
- Java基础系列--static关键字
原创作品,可以转载,但是请标注出处地址:http://www.cnblogs.com/V1haoge/p/8477914.html 一.概述 static关键字是Java诸多关键字中较常使用的一个,从 ...
- C#获取文件夹下的所有文件的文件名(转载)
String path = @"X:\xxx\xxx"; //第一种方法 var files = Directory.GetFiles(path, "*.txt&qu ...