IcerainLikes strings very much. Especially the strings only consist 0 1 of and, she call them easy strings. One day, she's so boring this she want to the find how many good substrings in a easy string?
A good substring is a substring which can are a palindrome string after your change any of the characters ' positions (you can Do the operation any times). For Example, is a good substring of 1001 , beacuse can change it to be < Span class= "Mathjax_preview" >010 , which is a palindrome string.
Input
The first line is the number of test cases. (No more than )
Each test case has a line containing one string with only consist of and 0 1 . The length of the string is no greater than 100000.
Output
For each test case, output one line contains the number of good substrings.
Sample Input and output
| Sample Input |
Sample Output |
20101101 |
211 |
Problem Solving Report
Prefix DP ... Thank Ching for your guidance.
1#include <iostream>2#include <cstring>3#include <algorithm>4 using namespacestd;5 Const intMAXN = 1e5 +5;6 intdp[4];7 CharBUFFER[MAXN];8 9 intMainintargcChar*argv[])Ten { One intCase ; Ascanf"%d",&Case ); - while(case--) - { thescanf"%s", buffer); - intLen =strlen (buffer); - Long LongAns =0; -Memset (DP,0,sizeof(DP)); + for(inti =1; I <= Len; ++i) - { + intFlag =0; A if(buffer[i-1] =='1') at { -Swap (dp[0],dp[1]); -Swap (dp[2],dp[3]); -Flag =1; - } - Else in { -Swap (dp[0],dp[3]); toSwap (dp[1],dp[2]); + } - if(flag) thedp[2] ++ ; * Else $dp[0] ++ ;Panax NotoginsengAns + = (dp[0] + dp[2] + dp[3]); - } thecout << ans <<Endl; + } A return 0; the}
Uestc_how many good substrings cdoj 1026