Western Subregional of NEERC, Minsk, Wednesday, November 4, 2015 Problem G. k-palindrome dp
题目连接:
http://opentrains.snarknews.info/~ejudge/team.cgi?SID=c75360ed7f2c7022&all_runs=1&action=140
Description
We will say that a string T is a k-palindrome for some positive integer k if and only if k is not grater than
the length of T and its prefix of the length k is equal to the reversed suffix of that length. For example,
abacaba is a k-palindrome for any k from 1 to 7 while abacabada is only 1-palindrome.
You are given a string S. Try to find the number of k-palindrome substrings of S for all k from 1 to the
length of S.
Input
The only line of input contains the string S (1 ≤ |S| ≤ 5000). The string contains only lowercase letters
of the Latin alphabet.
Output
Output |S| integers, the kth of them should be equal to the number of k-palindrome substrings of S.
Sample Input
abacaba
Sample Output
14 5 5 2 2 1 1
Hint
题意
k回文串就是表示这个串的前k个字符和后k个字符是回文的。
然后给你一个人串,问你他的k回文子串有多少个,k从1到n
题解:
首先k回文串的话,那么他一定是k-1回文串,所以只要知道最长的就好了。
枚举起点枚举终点,hash二分,这个复杂度n^2logn
但是可以n^2,就用dp去预处理起点和终点的最长前后缀,这个傻逼dp就好了。
代码
#include <bits/stdc++.h>
#define rep(a,b,c) for(int (a)=(b);(a)<=(c);++(a))
#define drep(a,b,c) for(int (a)=(b);(a)>=(c);--(a))
#define pb push_back
#define mp make_pair
#define sf scanf
#define pf printf
#define two(x) (1<<(x))
#define clr(x,y) memset((x),(y),sizeof((x)))
#define dbg(x) cout << #x << "=" << x << endl;
const int mod = 772002;
int mul(int x,int y){return 1LL*x*y%mod;}
int qpow(int x , int y){int res=1;while(y){if(y&1) res=mul(res,x) ; y>>=1 ; x=mul(x,x);} return res;}
inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;}
using namespace std;
const int maxn = 5000 + 50;
int f[maxn][maxn],len,ans[maxn];
char str[maxn];int DFS(int l , int r){if(~f[l][r]) return f[l][r];if(l>len||r<=0) return f[l][r]=0;if(str[l]==str[r]) f[l][r] = DFS(l+1,r-1)+1;else f[l][r] = 0;return f[l][r];
}int main( int argc , char * argv[] ){//freopen("in.txt","r",stdin);sf("%s",str+1);len=strlen(str+1);memset(f,-1,sizeof(f));for(int i = 1 ; i <= len ; ++ i) for(int j = i ; j <= len ; ++ j) ans[min(j-i+1,DFS(i,j))]++;for(int i = len ; i >= 1 ; -- i) ans[i - 1] += ans[i];for(int i = 1 ; i <= len ; ++ i){if( i > 1 ) pf(" ");pf("%d",ans[i]);}pf("\n");return 0;
}
Western Subregional of NEERC, Minsk, Wednesday, November 4, 2015 Problem G. k-palindrome dp相关推荐
- Western Subregional of NEERC, Minsk, Wednesday, November 4, 2015 Problem H. Parallel Worlds 计算几何...
Problem H. Parallel Worlds 题目连接: http://opentrains.snarknews.info/~ejudge/team.cgi?SID=c75360ed7f2c7 ...
- 【GYM101409】2010-2011 ACM-ICPC, NEERC, Western Subregional Contest
A-Area and Circumference 题目大意:在平面上给出$N$个三角形,问周长和面积比的最大值. #include <iostream> #include <algo ...
- Problem G. Graph 2015-2016 acmicpc neerc 拓扑排序模拟
一道好题 题目详见题目连接G graph 显然模拟拓扑排序的步骤是必不可少了. 假设我们当前有t个点,他们的入度均为0.我们不知道该选取哪一个. 我们把这t个点按从小到大排好序(放入小顶堆),假设我们 ...
- TensorFlow – A Collection of Resources
from: http://tm.durusau.net/?p=65606 Another Word For It Patrick Durusau on Topic Maps and Semantic ...
- 日常英语---七、[Updated November 14 at 4:10 PM PST] Scheduled Game Update - November 14, 2018(n.标准)...
日常英语---七.[Updated November 14 at 4:10 PM PST] Scheduled Game Update - November 14, 2018(n.标准) 一.总结 一 ...
- 计算机专业博士推荐信,计算机专业博士推荐信.doc
计算机专业博士推荐信 篇一:计算机专业留学推荐信5封~~~高含金量!! Dear Sir/Madam, I am writing this reference at the request of Al ...
- Full_of_Boys训练5总结
题目来源:2017-2018 ACM-ICPC, NEERC, Moscow Subregional Contest A. Advertising Strategy 贪心方法:把一部分k放到初始值,剩 ...
- MySQL date_format()函数
转载自 MySQL date_format()函数 MySQL DATE_FORMAT函数简介 要将日期值格式化为特定格式,请使用DATE_FORMAT函数. DATE_FORMAT函数的语法如下 ...
- java i18n实例_Java国际化(i18n)格式化日期
本篇文章帮大家学习java国际化(i18n)格式化日期,包含了Java国际化(i18n)格式化日期使用方法.操作技巧.实例演示和注意事项,有一定的学习价值,大家可以用来参考. DateFormat类提 ...
最新文章
- POJ-1185 炮兵阵地 动态规划+状态压缩
- centos7grub配置文件及排错
- python---webRTC~vad静音检测-学习笔记
- Ubuntu之Pycharm:Ubuntu系统内Pycharm安装的图文教程
- 云计算基础介绍,比喻小理解!
- dup、dup2、fcntl
- mock 生成在线图片
- python-面向对向编程-小结
- ASUS F9系列XP硬件驱动
- 解决:PHP Deprecated: Comments starting with '#' are deprecated in ……
- 论文整理:Probabilistic Logic Neural Networks for Reasoning
- 天翼云主机利用filezilla部署FTP服务器
- oracle添加触发器权限,Oracle 'after create'触发器授予权限
- “人工智能基础”课程笔记
- jmeter登录压力测试单用户和多用户登录
- 华南x79主板u盘装系统教程_[Hackintosh] X79黑苹果
- Android集成QQ登录
- 【520521】程序员中的“芳心纵火犯”, 这就是面向对象编程吗?
- 有什么编辑图片加文字的软件?今日推荐:图片编辑软件加文字
- 【adb】adb push命令 向设备传输文件