###### hdu5672 string(尺取法)

String
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1332 Accepted Submission(s): 445

Problem Description
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

#include<cstdio>
#include<cstring>

const int maxn=1000005;
char a[maxn];
int dig[27];

int main() {
int T;
scanf("%d",&T);
while(T--) {
int k;
memset(a,0,sizeof(a));
scanf("%s%d",a,&k);
int len=strlen(a);
long long ans=0;
memset(dig,0,sizeof(dig));
int s=0,t=-1,num=0;
while(t<len&&s<len) {
while(num<k&&(++t)<len) {
if(!dig[a[t]-'a'])++num;
++dig[a[t]-'a'];
}
if(num==k)
ans+=(len-t);
if(--dig[a[s]-'a']==0)--num;
++s;
}
printf("%lld\n",ans);
}
return 0;
}


#### hdu5672 String(尺取法)

2016-04-24 17:30:59

#### hdu5672尺取法

2016-07-31 18:10:00

#### HDU5672(尺取法)

2016-04-24 00:17:44

#### HDU 5672 String【尺取法】

2016-04-23 09:33:24

#### String HDU5672

2016-04-24 07:39:37

#### codeforces 778D. String Game (二分搜索)

2017-02-27 19:13:09

#### 算法学习之尺取法

2016-07-31 16:56:25

#### Codeforces Round #354 (Div. 2) C Vasya and String（尺取法二分）

2016-05-26 22:08:37

#### ACM常用的解题技巧：尺取法

2016-08-28 22:34:49

#### POJ 3276 Face The Right Way （常用技巧-尺取法）

2015-08-26 16:37:39

## 不良信息举报

hdu5672 string(尺取法)