DP VK Cup 2012 Qualification Round D. Palindrome pairs
题目地址: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的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- VK Cup 2016 - Qualification Round 2 B. Making Genome in Berland
今天在codeforces上面做到一道题:http://codeforces.com/contest/638/problem/B 题目大意是:给定n个字符串,找到最短的字符串S使得n个字符串都是这个字 ...
- VK Cup 2015 - Qualification Round 1 D. Closest Equals 离线+线段树
题目链接: http://codeforces.com/problemset/problem/522/D D. Closest Equals time limit per test3 secondsm ...
- 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 ...
- 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 ...
随机推荐
- dedecms如何随机调用指定分类下的文章到网站首页
dedecms是全静态的,有时会因为其他事情好几天没写文章推荐到首页,那样对se不是很友好.原本ytkah是想在网站首页上半部分调用几篇id从200到500的文章随机展示的,这样每次更新首页给se的赶 ...
- 在Linux用户空间做内核空间做的事情
导读 我相信,Linux 最好也是最坏的事情,就是内核空间(kernel space)和用户空间(user space)之间的巨大差别.如果没有这个区别,Linux 可能也不会成为世界上影响力最大的操 ...
- 新一代 Tor发布,它牛在哪里?
导读 知名匿名搜索引擎Tor,最近发布了基于火狐浏览器45-ESR的6.0版本,增强了对HTML5的支持,并更新了用来保护加密流量及其更新机制的安全功能.火狐45-ESR版本的全称为Firefox E ...
- 将linux用在开发环境中
我是如何将linux用在开发环境中的 1.为什么不直接安装Linux在主机 一直想深入学习一下linux的使用,于是将家里的笔记本装了linux系统,但是要将自己的系统打造一个适合开发的环境确实是一件 ...
- poj3259 bellman——ford Wormholes解绝负权问题
Wormholes Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 35103 Accepted: 12805 Descr ...
- Decompiled .class file,bytecode version:51.0(Java 7) Source for 'Android API 23 Platform' not found
今天在Android Studio中访问Java源码的时候,代码上方出现如下提示: 而且方法体中显示介样内容: throw new RuntimeException("Stub!" ...
- petri网学习心得
本文转载自duxw,如给您带来不便之处,请联系博主. 1.Petri网书籍:<petri网导论>,吴哲辉 非常适合初学者.概念清晰,容易理解. 2.工作流书籍:<Workflow M ...
- 【转】solr+ajax智能拼音详解---solr跨域请求
本文转自:http://blog.csdn.net/wangzhaodong001/article/details/8529090 最近刚做完solr的ajax智能拼音.总结一下. 前端:jQuery ...
- SQL 删除存在于A表但是不存在B表中的记录
目的是是的A表和B表某一个列集合相等 delete from A where tagetColumn not in ( select targetColumn from B)
- ubuntu 安装tigervnc
root@iZ25q0jd99eZ:~# apt-get install tigervnc Reading package lists... Done Building dependency tree ...