回文串的组合 DP

来源:互联网 发布:java中的流 编辑:程序博客网 时间:2024/05/29 19:14
D. Palindrome pairs
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a non-empty string s consisting of lowercase letters. Find the number of pairs of non-overlapping palindromic substrings of this string.

In a more formal way, you have to find the quantity of tuples (a, b, x, y) such that 1 ≤ a ≤ b < x ≤ y ≤ |s| and substrings s[a... b],s[x... y] are palindromes.

palindrome is a string that can be read the same way from left to right and from right to left. For example, "abacaba", "z", "abba" are palindromes.

substring s[i... j] (1 ≤ i ≤ j ≤ |s|) of string s = s1s2... s|s| is a string sisi + 1... sj. For example, substring s[2...4] of string s = "abacaba" equals "bac".

Input

The first line of input contains a non-empty string s which consists of lowercase letters ('a'...'z'), s contains at most 2000 characters.

Output

Output a single number — the quantity of pairs of non-overlapping palindromic substrings of s.

Please do not use the %lld format specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d format specifier.

Examples
input
aa
output
1
input
aaa
output
5
input
abacaba
output
36






题目大意:

回文串的组合

http://codeforces.com/contest/159/problem/D



思路:
虽然表示题解说的挺详细了,但是敲起来的时候还是遇到了各种问题

首先我们定义p[j][i]代表j到i是否是会问,然后用dp[i]来保存j<i的回文总数就好了


0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 老师打学生被家长起诉怎么办 家长在学校打了老师怎么办 老师打小孩我们家长怎么办呢? 孩子长手、腿毛怎么办 腿毛又黑又多怎么办 孩子怕老师说他怎么办 被老师骂到厌学怎么办 孩子对写作业一点也不主动怎么办 高三孩子太贪玩怎么办 玩心重的孩子该怎么办 儿子读大学不愿意读书怎么办 孩子打架全班都讨厌怎么办 孩子不爱学习怎么办 二年级 二年级孩子不爱学习总爱玩怎么办 初三孩子学习不积极怎么办 孩子学习不积极应该怎么办 小孩子贪玩不写作业怎么办 老公懒不帮忙分担家务怎么办 宝宝不喜欢早教课程单一怎么办 孩子上课不听话顶撞老师怎么办 孩子不喜欢吃水果蔬菜怎么办 中学生顶撞家长顶撞老师怎么办 .cn孩子初中上课不专心怎么办 娃儿小学二年级做不来怎么办 孩子不愿意看书沉迷电子产品怎么办 孩子自律和自控性差怎么办 婴儿7个月不喜欢吃东西怎么办 半岁宝宝太活泼怎么办 6个月宝宝太活泼怎么办 做nt宝宝太活跃怎么办 静不下心来学习怎么办 初中的孩子不爱学习怎么办 小孩不爱读书不做作业怎么办 母亲性格内向儿子也是内向怎么办 我儿子不爱吃怎么办啊 孩子练字就是记不住怎么办 孩子不愿意和小朋友玩怎么办 丈夫去世了婆婆不喜欢儿媳妇怎么办 高考看不下去书怎么办 在东莞读书读不成高中怎么办 嗓子哑了怎么办土方法