⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 p1876_dp.cpp

📁 高手写的所有acm例程 在acm.zju.edu.cn 上的题目的例程
💻 CPP
字号:
#include <stdio.h>
#include <string>
#include <string.h>
#include <map>

#define Self  'Z'
#define Indentify 'A'

using namespace std;

typedef  map < string , int > TMap;


TMap     Dic;
TMap     :: iterator Iter;


main ()
{
     Dic.clear ();
     
     char      Str [20];
     int       len , Final = 0 , Max , i;
     string    State , NewState;
     while ( scanf ( "%s\n" , Str ) != EOF ) {
           State = (string) Str;
           
           len = State.length () , Max = 0;
           
           NewState = State + Self;
           for ( i = 0; i <= len; i ++ ) {
               NewState [len] = Indentify + i;
               Iter = Dic.find ( NewState );
               if ( Iter != Dic.end () && Iter->second > Max ) Max = Iter->second;
           }   // part 1 : Insert
           
           NewState = State.substr ( 1 , len - 1 ) + Self;
           for ( i = 0; i < len; i ++ ) {
               if ( i ) NewState [i - 1] = State [i - 1];
               NewState [len - 1] = Indentify + i;
               Iter = Dic.find ( NewState );
               if ( Iter != Dic.end () && Iter->second > Max ) Max = Iter->second;
               
               NewState [len - 1] = Self;
               Iter = Dic.find ( NewState );
               if ( Iter != Dic.end () && Iter->second > Max ) Max = Iter->second;
           }
           
           Max ++;
           NewState = State + Self;
           Iter = Dic.find ( NewState );
           if ( Iter == Dic.end () ) Dic [NewState] = Max;
           else if ( Max > Iter->second ) Iter->second = Max;
           
           NewState = State.substr ( 1 , len - 1 ) + Self;
           for ( i = 0; i < len; i ++ ) {
               if ( i ) NewState [i - 1] = State [i - 1];
               NewState [len - 1] = Indentify + i;
               Iter = Dic.find ( NewState );
               if ( Iter == Dic.end () ) Dic [NewState] = Max;
               else if ( Max > Iter->second ) Iter->second = Max;
           }
           
           if ( Max > Final ) Final = Max;
     }
     
     printf ( "%d\n" , Final );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -