Click to open the link
Question:
For a string with a maximum length of 10000, ask how many response substrings it has (no need to be consecutive ).
If the substring is taken from different locations but identical, it is also different.
Analysis:
F [I] [J] indicates the string I ~ How many different substrings does segment J have?
Then f [I] [J] = f [I] [J-1] + F [I + 1] [J]-f [I + 1] [J-1]
If STR [I] = STR [J], add
F [I] [J] = f [I] [J] + F [I + 1] [J-1] + 1;
Code:
# Include <iostream> # include <cstdio> # include <cstring> # include <cmath> # include <algorithm> # include <vector> using namespace STD; typedef long int64; const int INF = 0x3f3f3f; const int maxn = 1010; const int mod = 10007; int f [maxn] [maxn], Len; char STR [maxn]; int main () {int t; int CAS = 1; scanf ("% d", & T); While (t --) {scanf ("% s", STR + 1 ); len = strlen (STR + 1); memset (F, 0, sizeof (f); For (INT I = 1; I <= Len; ++ I) f [I] [I] = 1; for (INT I = 1; I <Len; ++ I) {If (STR [I] = STR [I + 1]) f [I] [I + 1] = 3; else f [I] [I + 1] = 2;} For (INT S = 3; S <= Len; ++ s) {for (INT L = 1; L + S-1 <= Len; ++ L) {int r = L + s-1; f [l] [r] = (F [l] [r-1] + F [L + 1] [r]-f [L + 1] [r-1] + mod) % MOD; If (STR [l] = STR [R]) f [l] [r] = (F [l] [r] + F [L + 1] [r-1] + 1 + mod) % MOD ;}} printf ("case % d: % d \ n", CAS ++, F [1] [Len]);} return 0 ;}