First, introduce the lower ruler
Http://blog.chinaunix.net/uid-24922718-id-4848418.html
The ruler is constantly changing the end point of the subscript when the card is given conditions.
#include <cstdio>
#include <iostream>
#include <string.h>
using namespace Std;
int main ()
{
int t,k,j,vis[27];
Char a[1000005];
cin>>t;
while (t--)
{
scanf ("%s", &a);
scanf ("%d", &k);
int l=0,temp,num=0,i=0;
Long long int ans=0;
memset (vis,0,sizeof (VIS));
int Len=strlen (a);
while (L<=i&&l<len)
{
while (i<len&&num<k)//This step is to control the end point
{
temp=a[i++]-' a ';
if (vis[temp]==0) num++;
vis[temp]++;
}
if (num<k) break;
ans+= (len-i+1);
temp=a[l]-' a ';//The process behind is to move the starting point slowly forward
vis[temp]--;
if (vis[temp]==0) num--;
l++;
}
printf ("%i64d\n", ans);
}
return 0;
}
Finally, let's say two points on this topic.
1. The requirement here is that different alphabetic numbers can be implemented with a tag array (note that the tag array is processed at the beginning of the move)
2. The title requires the number of all subquence, and then in the simplest of times, some of it needs to be added.
Hdu 5672 feet It's pretty good.