HDU 1251統計的な問題(接頭辞を頼む何回も登場)

トピックへのリンク:http://acm.hdu.edu.cn/showproblem.php?pid=1251

#include <iostreamの> 
する#include <CStringの> 
する#include <cstdioを>
 の#define MEM(A、B)のmemset(A、B、はsizeof(a)参照)。
使用して 名前空間はstdを、
typedefの長い 長いLL。
const  int型 MAXN = 500005 ;
constの LL INF = 0x3f3f3f3f INTの TOT、N、トライ[MAXN] [ 26 ]、和[MAXN]。
BOOL VIS [MAXN]、フラグ。
ボイド挿入(CHAR * sで、INT RT)
{ 
    int型 LEN = STRLEN(S)。
    以下のためのint型I = 0 ; 私はLEN <; I ++ 
    { 
        int型のk = sの[I] - [ A ' もし(トライ[RT] [K] == 0)トライ[RT] [K] = ++ TOT。
        和[トライ[RT] [K] ++ ; 
        RT = トライ[RT] [K]。
    } 
} 
int型(検索文字 * sで、INT RT)
{ 
    int型 LEN = STRLEN(S)。
    以下のためにint型 i = 0 ; iがLEN <; iは++ 
    { 
        int型のk = S [I] - [" ; 
        RT = トライ[RT] [K]。
        もし(RT == 0の戻り 0 ; 
    } 

    戻り値の和[RT]。
} 
int型のmain()
{ 
    TOT = 0 int型 RT = 0 ; 
    フラグ = ;
    チャー S [ 105 ]。
    ながら、1 
    { 
        (S)を取得し、
        もし(S [ 0 ] == NULL)
        { 
            ブレイク; 
        } 
            挿入(S、RT)。
    } 
    一方(CIN >> S){ 
            COUT <<(RT、S)検索<< ENDL。
    } 
    戻り 0 
}

 

おすすめ

転載: www.cnblogs.com/LLLAIH/p/11330433.html