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
這個(gè)題目一開(kāi)始理解錯(cuò)了,看了解釋之后才知道是什么意思。題目的本意是要尋找前k個(gè)字母出現(xiàn)次數(shù)最長(zhǎng)的子字符串。只要找出出現(xiàn)次數(shù)最少的那一個(gè),然后乘以k就可以了。上代碼,嚶嚶嚶。
每天少做一個(gè)題,都要說(shuō)聲對(duì)不起。┭┮﹏┭┮
總結(jié)
以上是生活随笔為你收集整理的codeforces 1038a(找最长的前k个字母出现相同次数的字符串)水题的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: codeforces 1040a (回文
- 下一篇: 青岛理工邀请赛(难受的一次经历)之显示屏