题目地址:http://blog.csdn.net/shiyuankongbu/article/details/10004443

 /*
题意:在i前面找回文子串,在i后面找回文子串相互配对,问有几对
DP:很巧妙的从i出发向两头扩展判断是否相同来找回文串
dpr[i] 代表记录从0到i间的回文子串的个数,dpl[i] 代表记录i之后的回文子串个数
两两相乘就行了
详细解释:http://blog.csdn.net/shiyuankongbu/article/details/10004443
*/
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <cstring>
#include <string>
#include <map>
#include <vector>
#include <set>
using namespace std; const int MAXN = + ;
const int INF = 0x3f3f3f3f;
string s;
int dpr[MAXN];
int dpl[MAXN]; bool ok(int x, int y)
{
int i, j;
for (i=x, j=y; i<=y && j>=x; ++i, --j)
{
if (s[i] != s[j]) return false;
} return true;
} int main(void) //VK Cup 2012 Qualification Round D. Palindrome pairs
{
//freopen ("D.in", "r", stdin); while (cin >> s)
{
memset (dpr, , sizeof (dpr));
memset (dpl, , sizeof (dpl));
long long ans = ;
int len = s.size (); for (int i=; i<len; ++i)
{
for (int j=i, k=i; j>=&&k<len&&s[j]==s[k]; --j, ++k)
{
dpl[j]++; dpr[k]++;
}
for (int j=i, k=i+; j>=&&k<len&&s[j]==s[k]; --j, ++k)
{
dpl[j]++; dpr[k]++;
}
} for (int i=; i<len; ++i)
dpr[i] += dpr[i-]; for (int i=; i<len-; ++i)
{
ans += dpr[i] * dpl[i+];
} cout << ans << endl;
} return ;
}

DP VK Cup 2012 Qualification Round D. Palindrome pairs的更多相关文章

  1. VK Cup 2012 Qualification Round 1 E. Phone Talks —— DP

    题目链接:http://codeforces.com/contest/158/problem/E E. Phone Talks time limit per test 3 seconds memory ...

  2. VK Cup 2012 Qualification Round 1 C. Cd and pwd commands 模拟

    C. Cd and pwd commands Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset ...

  3. VK Cup 2012 Qualification Round 2 C. String Manipulation 1.0 字符串模拟

    C. String Manipulation 1.0 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 codeforces.com/problemset/pr ...

  4. VK Cup 2012 Qualification Round 1---C. Cd and pwd commands

    Cd and pwd commands time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  5. VK Cup 2015 - Qualification Round 1 A. Reposts [ dp DAG上最长路 ]

    传送门 A. Reposts time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  6. VK Cup 2016 - Qualification Round 2 B. Making Genome in Berland

    今天在codeforces上面做到一道题:http://codeforces.com/contest/638/problem/B 题目大意是:给定n个字符串,找到最短的字符串S使得n个字符串都是这个字 ...

  7. VK Cup 2015 - Qualification Round 1 D. Closest Equals 离线+线段树

    题目链接: http://codeforces.com/problemset/problem/522/D D. Closest Equals time limit per test3 secondsm ...

  8. VK Cup 2016 - Qualification Round 2 D. Three-dimensional Turtle Super Computer 暴力

    D. Three-dimensional Turtle Super Computer 题目连接: http://www.codeforces.com/contest/638/problem/D Des ...

  9. VK Cup 2016 - Qualification Round 2 C. Road Improvement dfs

    C. Road Improvement 题目连接: http://www.codeforces.com/contest/638/problem/C Description In Berland the ...

随机推荐

  1. 阿里云vps上mysql挂掉的解决办法

    阿里云vps上mysql挂掉的解决办法 4条回复 用阿里云的vps用作blog服务器,系统很稳定,已经100多天一直运行正常,大概从上个月开始发现blog的mysql会有时挂掉,会收到短信通知.之前没 ...

  2. FlashDevelop快捷键

    将鼠标点到变量上面后,同时按ctrl+shift+1(左键盘),可以自动添加变量或者函数.复制一行代码.CTRL+D:ctrl+shift+k 颜色代码拾取器 ctrl+shift+b 注释年选代码段 ...

  3. 《ASP.NET1200例》ListView 控件与DataPager控件的结合<二>

    ASP.NET使用ListView数据绑定控件和DataPager实现数据分页显示 为什么使用ListView+DataPager的方式实现分页显示? .net提供的诸多数据绑定控件,每一种都有它自己 ...

  4. DP:Corn Fields(POJ 3254)

    北大教你如何高效养牛(误)(点我查看)  2015-08-21: 问题的大意就是有一片稻田,里面有很多坑,你要在上面种稻谷,然后呢田里面还会养牛,牛不喜欢扎堆吃饭,所以呢你种的稻谷要间隔种在坑里面,所 ...

  5. codeforces 485A.Factory 解题报告

    题目链接:http://codeforces.com/problemset/problem/485/A 题目意思:给出 a 和 m,a 表示第一日的details,要求该日结束时要多生产 a mod ...

  6. poj 1007 DNA Sorting 解题报告

    题目链接:http://poj.org/problem?id=1007 本题属于字符串排序问题.思路很简单,把每行的字符串和该行字符串统计出的字母逆序的总和看成一个结构体.最后把全部行按照这个总和从小 ...

  7. ubuntu下Tomcat7的安装和配置

    和前几个软件一样,Tomcat 同样是由JAVA开发的,所以,在安装前一定要装好JDK. 大家可以到 http://tomcat.apache.org/download-70.cgi 下载最新的Tom ...

  8. Sass 中的 @ 规则

    一. @import Sass 扩展了 CSS 的 @import 规则,让它能够引入 SCSS 和 Sass 文件. 所有引入的 SCSS 和 Sass 文件都会被合并并输出一个单一的 CSS 文件 ...

  9. java关闭流,解压缩后的清除

    关闭流文件和file文件的时候,先打开的后关闭,后打开的先关闭,实在不行调用system.jc()方法

  10. angularjs 指令(directive)详解(2)

    原文地址 上一篇我们说到了transclude,那么,我们现在继续讲解之后的内容. 9.scope 可选参数,默认值为false.取值: false - 在这个directive里不会创建新的scop ...