[Dictionary tree] poj 2418 Hardwood Species

Source: Internet
Author: User

Xiaodi

Some people know how to break ce when SZ = 1 is added to trie ??? Can someone teach me ?? I still don't know how C ++ is weak. Thank you very much! Orz

# Include <stdio. h> # include <stdlib. h> # include <string. h> # include <ctype. h> # include <math. h ># include <string >#include <iostream> # include <algorithm> using namespace STD; # include <queue> # include <stack> # include <vector> # include <deque> # include <set> # include <map> # define word_len 1000010 # define sigma_size 128 typedef struct trie {int ch [word_len] [sigma_size]; // word_len indicates the number of nodes in the dictionary tree. If all nodes are lowercase letters, sigma_size = 26 int have_word [word _ Len]; // There are several words in this node: int SZ; trie () {// here !!!~~~~~ Memset (CH, 0, sizeof (CH); memset (have_word, 0, sizeof (have_word) ;}; trie AC; int tol; void insert (char * s) // Add the V number to the last letter of the S word {int u = 0, Len = strlen (s); For (INT I = 0; I <Len; I ++) {int c = s [I]; If (! AC. ch [u] [c]) // If the node does not exist, add the AC after the node is created. ch [u] [c] = ac. SZ ++; u = ac. ch [u] [c];} AC. have_word [u] ++; // The current U is the last position of the word} Char s [222]; void find (int x, int K) {for (INT I = 0; I <128; I ++) {If (AC. ch [x] [I]) {Int J = ac. ch [x] [I]; s [k] = I; If (AC. have_word [J]) {s [k + 1] = '\ 0'; printf ("% S %. 4lf \ n ", S, AC. have_word [J] * 100.0/TOL);} Find (j, k + 1) ;}} int main () {char C [222]; Tol = 0; AC. SZ = 1; while (gets (c) & C [0]) {insert (c); Tol ++;} Find (0, 0); Return 0 ;}

[Dictionary tree] poj 2418 Hardwood Species

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.