Title Link: Http://codeforces.com/contest/676/problem/C
A string containing only A and B, you can change the K, to find the most beautiful value, the beauty value is defined as the substring contains the same characters of the oldest string length
Topic Analysis: Define the starting point and end point, direct greed. For K-Times operation, either full-or full-change B, the two cases to take the maximum, the calculation of the time with a two-point method, R right until K runs out, and then L from the left to add, constantly restore K value (because it is a substring of changes, to make the substring the longest, Then change the character must be in the order in which the change is continuous in the middle can not have no change)
The code is as follows:
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <vector>
using namespace std;
typedef __int64 LL;
Double dp[12][12];
int n, K;
String str;
int solve (char ch)
{
int l = 0, r = 0, ans = 0, cnt = 0;
while (R < n && L < N)
{while
((str[r] = = CH | | cnt < k) && R < N)//Find the location of the right endpoint
{
if (str[r]! = ch) cnt++;
r++;
}
ans = max (ans, r-l);
while (l<=r && str[l] = = ch) The left end of the l++;//substring is shifted to the right
l++;
cnt--;
}
return ans;
}
int main ()
{
while (scanf ("%d%d", &n, &k)! = EOF)
{
cin>>str;
printf ("%d\n", Max (Solve (' a '), Solve (' B ')));
}
return 0;
}