codeforces 1038a(找最长的前k个字母出现相同次数的字符串)水题
http://codeforces.com/problemset/problem/1038/A(題目鏈接)
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≤1e5) 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.
Examples
input
9 3
ACAABCCAB
output
6
input
9 4
ABCABCABC
output
0
這個題目一開始理解錯了,看了解釋之后才知道是什么意思。題目的本意是要尋找前k個字母出現次數最長的子字符串。只要找出出現次數最少的那一個,然后乘以k就可以了。上代碼,嚶嚶嚶。
每天少做一個題,都要說聲對不起。┭┮﹏┭┮
總結
以上是生活随笔為你收集整理的codeforces 1038a(找最长的前k个字母出现相同次数的字符串)水题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: codeforces 1040a (回文
- 下一篇: 青岛理工邀请赛(难受的一次经历)之显示屏