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

分析: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. python笔记-邮件发送(smtplib)【转载】

    本篇转自博客:上海-悠悠 原文地址:http://www.cnblogs.com/yoyoketang/tag/python/ 前言 本篇总结了QQ邮箱和163邮箱发送邮件,邮件包含html中文和附件 ...

  2. eclipse断点调试基础

    进入debug模式: 1.设置断点 2.启动servers端的debug模式 3.运行程序,在后台遇到断点时,进入debug调试状态 ============================= 作用域 ...

  3. [BZOJ4537][Hnoi2016]最小公倍数 奇怪的分块+可撤销并查集

    4537: [Hnoi2016]最小公倍数 Time Limit: 40 Sec  Memory Limit: 512 MBSubmit: 1474  Solved: 521[Submit][Stat ...

  4. AC日记——[Ahoi2013]作业 bzoj 3236

    3236 思路: 莫队+树状数组维护: 代码: #include <cmath> #include <cstdio> #include <cstring> #inc ...

  5. 【转.解析清晰】你真明白 Python 装饰器么?

      原文出处: 武沛齐    装饰器是程序开发中经常会用到的一个功能,用好了装饰器,开发效率如虎添翼,所以这也是Python面试中必问的问题,但对于好多小白来讲,这个功能 有点绕,自学时直接绕过去了, ...

  6. CentOS中文乱码解决办法

    打开文件:/etc/sysconfig/i18n ,对其中相关属性配置修改成如下: LANG="zh_CN.GB18030" LANGUAGE="zh_CN.GB1803 ...

  7. CF 1003C Intense Heat【前缀和/精度/双层暴力枚举】

    The heat during the last few days has been really intense. Scientists from all over the Berland stud ...

  8. Proxy(2016山东省省赛C)(最短路)(spfa)

    问题 C: Proxy 时间限制: 2 Sec  内存限制: 128 MB提交: 17  解决: 5[提交][状态][讨论版] 题目描述 Because of the GFW (Great Firew ...

  9. oracle enable / disable all constraint

    beginfor i in (select constraint_name, table_name from user_constraints where table_name='') LOOPexe ...

  10. luogu P1855 榨取kkksc03

    题目描述 以下皆为真实的故事. 洛谷2的团队功能是其他任何oj和工具难以达到的.借助洛谷强大的服务器资源,任何学校都可以在洛谷上零成本的搭建oj并高效率的完成训练计划. 为什么说是搭建oj呢?为什么高 ...