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就可以了。上代码,嘤嘤嘤。

#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;
}

每天少做一个题,都要说声对不起。┭┮﹏┭┮

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

starlet_kiss

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值