Hdu 5672 feet It's pretty good.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.