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

分析: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. EAScript 2016的新增语法(1)

    1)let 语法,这个和var的声明类似,但是,只存在于其所在的代码块里. 举例: var x=1 console.log(x) { let x=2 console.log(x) } console. ...

  2. ajax按钮改变数据状态

    1.html代码 <td> @if($project->done_deal==) <button type="button" class="btn ...

  3. Codeforces Round #424 B. Keyboard Layouts(字符串,匹配,map)

    #include <stdio.h> #include <string.h> ][]; ]; ]; int main(){ scanf(]); scanf(]); scanf( ...

  4. Problem A: 英雄无敌3(1)【dp/待补】

      Problem A: 英雄无敌3(1) Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 86  Solved: 16[Submit][Status][ ...

  5. Gitlab运维

    安装Gitlab 新建 /etc/yum.repos.d/gitlab-ce.repo [gitlab-ce] name=gitlab-ce baseurl=http://mirrors.tuna.t ...

  6. 【分块】bzoj3295 [Cqoi2011]动态逆序对

    考虑每次删除pos位置一个数x后,所造成的的影响就是,逆序对的个数少了在1~pos-1中大于x的数的个数加上pos+1~n中小于x的数的个数. 那么我们需要的操作就只有查询区间内比某数大(小)的个数. ...

  7. TZOJ 删除前导多余的*号

    描述 规定输入的字符串中只包含字母和*号,编写程序使字符串中前导的*号不得多于n个:若多于n个,则删除多余的*号:若少于或等于n个,则什么也不做,字符串中间和尾部的*号不删除. 输入 输入数据包括一串 ...

  8. Problem O: 逆序输出——C语言初学者百题大战之二十

    #include<stdio.h> int main() { int a,b,c,d,e,n; scanf("%d",&n); a=n/; b=n%/; c=n ...

  9. WebService authentication

    http://blog.csdn.net/largestone_187/article/details/5734632 通过SoapHeader对用户口令进行验证,只有授权的用户才可以使用接口.确保了 ...

  10. 解决IIS服务和用户上传的文件分别部署在不同的电脑上时,解决权限的问题

    为解决IIS服务和用户上传的文件分别部署在不同的电脑上时,解决权限的问题. 定义: A:iis服务器 B:文件服务器 步骤: 1.在B上创建一个用户[uploaduser](并设置密码) 2.给B上的 ...