日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

codeforces 1038a(找最长的前k个字母出现相同次数的字符串)水题

發(fā)布時(shí)間:2023/12/15 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 codeforces 1038a(找最长的前k个字母出现相同次数的字符串)水题 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

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è)題目一開始理解錯(cuò)了,看了解釋之后才知道是什么意思。題目的本意是要尋找前k個(gè)字母出現(xiàn)次數(shù)最長(zhǎng)的子字符串。只要找出出現(xiàn)次數(shù)最少的那一個(gè),然后乘以k就可以了。上代碼,嚶嚶嚶。

#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #define inf 0x3f3f3f3f using namespace std;const int maxx=1e5+10; char a[maxx]; int b[maxx]; int n,k;int main() {while(cin>>n>>k){cin>>a;int minn=inf;for(int i=0;i<n;i++) b[a[i]-'A'+1]++;for(int i=1;i<=k;i++)minn=min(b[i],minn);cout<<k*minn<<endl;}return 0; }

每天少做一個(gè)題,都要說(shuō)聲對(duì)不起。┭┮﹏┭┮

總結(jié)

以上是生活随笔為你收集整理的codeforces 1038a(找最长的前k个字母出现相同次数的字符串)水题的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。