题目地址: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. js打印(控件)及多种方式

    非常好用的LODOP打印控件 Lodop打印控件简单使用方法 1.安装. 2.调用LodopFuncs.js文件. 3.增加OBJECT对象 <script language="jav ...

  2. $gte 必须使用双引号,且冒号后面不能有空格

    pry(main)> puts "showlastupdate:{\"$gte\":\"#{Date.today.to_s(:number)}\" ...

  3. Android 下载文件及写入SD卡

    Android 下载文件及写入SD卡,实例代码 <?xml version="1.0" encoding="utf-8"?> <LinearL ...

  4. Linux下crontab命令的用法

    cron来源于希腊单词chronos(意为“时间”),是linux系统下一个自动执行指定任务的程序.例如,你想在每晚睡觉期间创建某些文件或文件夹的备份,就可以用cron来自动执行. 服务的启动和停止 ...

  5. linux里的vi怎么移动到最后一行

    下面是几个vi与行移动有关的命令: G:光标移至最后一行 nG:光标移至第n行首 n+:光标下移n行 n-:光标上移n行 注意输入命令,需要首先按ESC键回到命令模式. 转自: http://zhid ...

  6. Datasets for Data Mining and Data Science

    https://github.com/mattbane/RecommenderSystem http://grouplens.org/datasets/movielens/ KDDCUP-2012官网 ...

  7. Bulls and Cows

    You are playing the following Bulls and Cows game with your friend: You write down a number and ask ...

  8. TexBox的属性

    允许多行输入

  9. 对于sharepoint 的解决方案的实际说明

    对于sharepoint 的解决方案  实际上就是cab的包 你把***.wsp改为***.cab我们就可以查看这个包中的所有内容了

  10. Java异常与异常处理简单使用

    异常就是程序运行过程中阻止当前方法或作用域继续执行的问题: 任何程序都不能保证完全正常运行,当发生异常时,需要我们去处理异常,特别是一些比较重要的场景,异常处理的逻辑也会比较复杂,比如:给用户提示.保 ...