hdu 5672
Updated:
Contents
hdu 5672
题目:
There is a string S.S only contain lower case English character.(10≤length(S)≤1,000,000)
How many substrings there are that contain at least k(1≤k≤26) distinct characters?
Input:
There are multiple test cases. The first line of input contains an integer T(1≤T≤10) indicating the number of test cases. For each test case:
The first line contains string S.
The second line contains a integer k(1≤k≤26).
Output:
For each test case, output the number of substrings that contain at least k dictinct characters.
Sample Input
2
abcabcabca
4
abcabcabcabc
3
Sample Output
0
55
题目大意:
有一个 10≤长度≤1,000,000 的字符串,仅由小写字母构成。求有多少个子串,包含有至少k(1≤k≤26)个不同的字母?
分析:
- 尺取法
我做的时候遇到的问题:
ans += len - j + 1;当前的状态已经满足,后面的元素可以构成的集合2^n - 1,为什么不是再加后面元素可构成的集合个数?
答:子串是连续的,所以不能向上面想的那样,上面那个考虑的是子序列的情况,那么尺取法也就不行了,尺取法也是在连续的基础上的
1 |
|