CF1930D1.Sum over all Substrings (Easy Version)
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
This is the easy version of the problem. The only difference between the two versions is the constraint on t and n . You can make hacks only if both versions of the problem are solved.
For a binary † pattern p and a binary string q , both of length m , q is called p -good if for every i ( 1≤i≤m ), there exist indices l and r such that:
- 1≤l≤i≤r≤m , and
- pi is a mode ‡ of the string qlql+1…qr .
For a pattern p , let f(p) be the minimum possible number of 1 s in a p -good binary string (of the same length as the pattern).
You are given a binary string s of size n . Find $$$$\sum_{i=1}^{n} \sum_{j=i}^{n} f(s_i s_{i+1} \ldots s_j). $$ In other words, you need to sum the values of f over all fracn(n+1)2 substrings of s .
^\\dagger A binary pattern is a string that only consists of characters mathtt0 and mathtt1 .
^\\ddagger Character c is a mode of string t of length m if the number of occurrences of c in t is at least lceilfracm2rceil . For example, mathtt0 is a mode of mathtt010 , mathtt1 is not a mode of mathtt010 , and both mathtt0 and mathtt1 are modes of mathtt011010$$.
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t ( 1≤t≤500 ) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer n ( 1≤n≤100 ) — the length of the binary string s .
The second line of each test case contains a binary string s of length n consisting of only characters 0 and 1 .
It is guaranteed that the sum of n2 over all test cases does not exceed 104 .
输出格式
For each test case, output the sum of values of f over all substrings of s .
输入输出样例
输入#1
4 1 1 2 10 5 00000 20 11110110000000111111
输出#1
1 2 0 346
说明/提示
In the first test case, the only 1 -good string is 1 . Thus, f(1)=1 .
In the second test case, f(10)=1 because 01 is 10 -good, and 00 is not 10 -good. Thus, the answer is f(1)+f(10)+f(0)=1+1+0=2 .
In the third test case, f equals to 0 for all 1≤i≤j≤5 . Thus, the answer is 0 .