zoukankan      html  css  js  c++  java
  • zoj 2744

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

    分析: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;
    }

  • 相关阅读:
    GPO
    GPO
    GPO
    Active Directory
    Active Directory
    Ethical Hacking
    Tree and Queries CodeForces
    数颜色 HYSBZ
    Powerful array CodeForces
    Group HDU
  • 原文地址:https://www.cnblogs.com/yjbjingcha/p/6806522.html
Copyright © 2011-2022 走看看