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;}