题目:统计一个串中的回文子串的个数(注意是子串,要连续)。

分析:dp。暴力。直接用dp,二维数组内存不够用,并且dp木有暴力快( ⊙ o ⊙ )啊!

说明:(2011-09-24 03:22)。

#include <iostream>
#include <cstdlib>
#include <cstring> using namespace std; char data[ 5005 ];
bool F[ 5005 ][ 5005 ]; int main()
{
while ( cin >> data ) {
int Len = strlen( data );
memset( F, false, sizeof( F ) );
for ( int i = 0 ; i < Len ; ++ i )
F[ i ][ i ] = true;
for ( int i = Len-1 ; i >= 0 ; -- i )
for ( int j = i+1 ; j < Len ; ++ j )
if ( data[ i ] == data[ j ] && ( i+1 >= j-1 || F[ i+1 ][ j-1 ] ) )
F[ i ][ j ] = true; int count = 0;
for ( int i = 0 ; i < Len ; ++ i )
for ( int j = i ; j < Len ; ++ j )
if ( F[ i ][ j ] ) ++ count; cout << count << endl;
}
return 0;
}

zoj 2744 - Palindromes的更多相关文章

  1. zoj 2744 Palindromes(计算回文子串个数的优化策略)

    题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2744 题目描述: A regular palindrome i ...

  2. ZOJ题目分类

    ZOJ题目分类初学者题: 1001 1037 1048 1049 1051 1067 1115 1151 1201 1205 1216 1240 1241 1242 1251 1292 1331 13 ...

  3. ZOJ People Counting

    第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ  3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...

  4. ZOJ 3686 A Simple Tree Problem

    A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a rooted tree, each no ...

  5. ZOJ Problem Set - 1394 Polar Explorer

    这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...

  6. ZOJ Problem Set - 1392 The Hardest Problem Ever

    放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...

  7. ZOJ Problem Set - 1049 I Think I Need a Houseboat

    这道题目说白了是一道平面几何的数学问题,重在理解题目的意思: 题目说,弗雷德想买地盖房养老,但是土地每年会被密西西比河淹掉一部分,而且经调查是以半圆形的方式淹没的,每年淹没50平方英里,以初始水岸线为 ...

  8. ZOJ Problem Set - 1006 Do the Untwist

    今天在ZOJ上做了道很简单的题目是关于加密解密问题的,此题的关键点就在于求余的逆运算: 比如假设都是正整数 A=(B-C)%D 则 B - C = D*n + A 其中 A < D 移项 B = ...

  9. ZOJ Problem Set - 1001 A + B Problem

    ZOJ ACM题集,编译环境VC6.0 #include <stdio.h> int main() { int a,b; while(scanf("%d%d",& ...

随机推荐

  1. quote(),unquote(),urlencode()编码解码

    quote(),unquote(),quote_plus(),unquote_plus(),urlencode() ,pathname2url(),url2pathname() urllib中还提供了 ...

  2. poj 2007(凸包)

    Scrambled Polygon Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 8005   Accepted: 3798 ...

  3. Laravel5.5配置使用redis

    1.安装redis linux上redis的安装与配置 2.安装redis客户端 composer require predis/predis或者安装 PhpRedis PHP 扩展brew inst ...

  4. Python3中的新特性(2)——常见陷阱

    1.文本与字节 Python3对文本字符串(字符)和二进制数据(字节)进行了严格区分,'hello'表示一个以Unicode编码保存的文本字符串,而b'hello'表示一个字节字符串. 在Python ...

  5. owasp zap 安全审计工具 功能详解

    一.persist session 该功能主要保存扫描分析的结果,方便下次继续分析 二.扫描策略 1.修改策略 A.入口 B.具体设置页面 C.设置完成后,发起主动扫描,在弹出的窗口可以选择策略 D. ...

  6. opencv中CV_IMAGE_ELEM的用法读取每个像素

    可以使用OpenCV定义的宏来提取象素值假设灰度图像image,存取其i行j列的象素可以这样:CV_IMAGE_ELEM(image, uchar,y, x)如果是彩色图像就是CV_IMAGE_ELE ...

  7. 2017 ACM-ICPC 亚洲区(青岛赛区)网络赛 1009

    #include<cmath> #include<set> #include<list> #include<deque> #include<map ...

  8. 二叉树学习三:AVL树

    1.AVL树: 1)其左子树(TL)与右子树(TR)是AVL树: 2)|HL-HR|<=1,其中HL和HR是TL和TR的高度: 3)高度为h的AVL树,结点数2*h-1. AVL树查找,插入,删 ...

  9. 23、Django实战第23天:视频播放页面

    打开素材course-play.html,会发现播放页面处了包含播放器,其他和“章节”页面一样. 1.把course-play.html复制到template目录下 2.把下面两段代码拷贝出来 < ...

  10. [BZOJ 1177] Oil

    Link:https://www.lydsy.com/JudgeOnline/problem.php?id=1177 Solution: 相当于将大矩形分为3块,取每块中最大的正方形 对于此类分成几块 ...