A - Equality

题干

You are given a string s of length n, which consists only of the first k letters of the Latin alphabet. All letters in string s are uppercase.
A subsequence of string s is a string that can be derived from s by deleting some of its symbols without changing the order of the remaining symbols. For example, “ADE” and “BD” are subsequences of “ABCDE”, but “DEA” is not.
A subsequence of s called good if the number of occurences of each of the first k letters of the alphabet is the same.
Find the length of the longest good subsequence of s.

Input

The first line of the input contains integers n (1≤n≤105) and k (1≤k≤26).
The second line of the input contains the string s of length n. String s only contains uppercase letters from ‘A’ to the k-th letter of Latin alphabet.

Output

Print the only integer — the length of the longest good subsequence of string s.

题解

输入之后找出前n个字母出现次数最少的k即为答案(不用管note里面的example2,因为0k还是0,没有影响不需要处理)

#include
using namespace std;
int n,k,a[30];
char s[100010];
int main()
{
    cin>>n>>k>>s;
    for(int i=0;i<n;i++)    a[s[i]-'A'+1]++;
    sort(a+1,a+k+1);
    cout<<a[1]*k<<endl;
    return 0;
}

你可能感兴趣的:(ACM集训)