题目地址: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. 微信公众平台开发(十) 消息回复总结——用其xml模板

    一.简介 微信公众平台提供了三种消息回复的格式,即文本回复.音乐回复和图文回复,在这一篇文章中,我们将对这三种消息回复的格式做一下简单讲解,然后封装成函数,以供读者使用. 二.思路分析 对于每一个PO ...

  2. Sed替换行和字符shell

    1.在某一行后面追加一行 RD=2000sed -i '/ssi_types/ a\limit_req zone=lreq burst='$RD';' /opt/bee.location 2.替换字符 ...

  3. [codeforces 260]B. Ancient Prophesy

    [codeforces 260]B. Ancient Prophesy 试题描述 A recently found Ancient Prophesy is believed to contain th ...

  4. lvs之nat技术的学习与实践

    lvs nat 服务器搭建 1.配置三个虚拟机.一台用于做lvs  两台用于做web server 进行测试 (lvs服务器要配备两块网卡); lvs 服务器  两块网卡 分别为vmnet1   vm ...

  5. PHP编译支持mysqli

    PHP编译支持mysqli前提是必须安装mysql直接上命令先进入源码包我的源码包是在/usr/local/php-5.2.1/ext/mysqli这样进入 cd /usr/local/php-5.2 ...

  6. MySQL使用索引的场景及真正利用索引的SQL类型

    1. 为什么使用索引 在无索引的情况下,MySQL会扫描整张表来查找符合sql条件的记录,其时间开销与表中数据量呈正相关.对关系型数据表中的某些字段建索引可以极大提高查询速度(当然,不同字段是否sel ...

  7. windows下安装Appserv等php套件之后无法进入数据库管理的问题

    在win7下安装Wamp或者Appserv后无法进入数据库管理,但是php.Apache运行全都没问题,mysql可以在命令行中管理,但是就是无法打开phpmyadmin数据库管理,点击后浏览器就显示 ...

  8. 【JAVA、C++】LeetCode 016 3Sum Closest

    Given an array S of n integers, find three integers in S such that the sum is closest to a given num ...

  9. Java数据类型中String、Integer、int相互间的转换

    1.Integer转换成int的方法 Integer i;  int k = i.intValue(); 即Integer.intValue(); 2.int转换成Integer int i; Int ...

  10. CUDA学习笔记(一)——CUDA编程模型

    转自:http://blog.sina.com.cn/s/blog_48b9e1f90100fm56.html CUDA的代码分成两部分,一部分在host(CPU)上运行,是普通的C代码:另一部分在d ...