Wikioi 1306 wit trie tree

Source: Internet
Author: User

Description Description

It's boring to watch radio exercises ~ Do you think? People who are watching Radio Exercises surge after wave and then exit. I think it's boring ...... As a result, our great god, mongojht, invented a game and its fun game ~

Think of the formation of each class as a letter (only uppercase letters can be used), and then bored into a string in their order of appearance, became a famous string! Jht God wants to see how many different appearance combinations are in a grade (lcz: To put it bluntly, it is to calculate the number of non-empty substrings in the string !).

Input description Input description

Line 1: String s

Output description Output description

Line 1: a number (the number of different non-empty substrings in S string)

Sample Input Sample Input

Aaabbbccc

Sample output Sample output

36

Data range and prompt Data size & hint

Time Limit

1 s for each of the first 8 points

1.5 s at next 2

String Length hint

10% of data: 1 ≤ string s length ≤ 100

80% of data: 1 ≤ string s length ≤ 1200

100% of data: 1 ≤ string s length ≤ 1500


This question is just getting a child string, then adding it to the trie tree, then t, t at the time of getting the child string, and then there is no more. Only when someone else's code is downloaded can you find the sub-string wit. For details, see the code.

#include <cstdio>#include <cstring>#include <algorithm>#include<iostream>#include<bitset>#define mem(a,b) memset(a,b,sizeof(a))using namespace std;char s[1505];int sum,i,j,len,u,ch[1200000][26];int main(){    scanf("%s",s);    len=strlen(s);    for(i=0;i<len;i++)    {        u=0;        for(j=i;j<len;j++)        {            int c=s[j]-'A';            if(!ch[u][c]) ch[u][c]=++sum;            u=ch[u][c];        }    }    cout<<sum<<endl;    return 0;}


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.