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

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

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

  1. C++100w个数中找出最大的前K个数

    /*100w个数中找出最大的前K个数*/ #include <iostream> using namespace std; #include <assert.h> const ...

  2. 小红拿到了一个仅由大小写字母组成的长度为n的字符串,她希望把前k个字母变成大写,后n- k个字母变成小写,你能帮帮她吗?

    小红拿到了一个仅由大小写字母组成的长度为n的字符串,她希望把前k个字母变成大写,后n- k个字母变成小写,你能帮帮她吗? 输入描述: 第一行输入两个正整数n和k,用空格隔开. 第二行输入一个长度为n的 ...

  3. codeforces 133A HQ9+(字符串水题)

    A. HQ9+ 点击打开题目 time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  4. Codeforces Round #309 (Div. 2) A. Kyoya and Photobooks 字符串水题

    A. Kyoya and Photobooks Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...

  5. Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) A. Bear and Game 水题

    A. Bear and Game 题目连接: http://www.codeforces.com/contest/673/problem/A Description Bear Limak likes ...

  6. codeforces 112APetya and Strings(字符串水题)

    A. Petya and Strings 点击打开题目 time limit per test 2 seconds memory limit per test 256 megabytes input ...

  7. Educational Codeforces Round 96 (Rated for Div. 2)C. Numbers on Whiteboard(贪心算法(水题))

    题目链接: 传送门 题目贴上: 题意:,给你 1-n个数,你可以对两个不同位置的数进行合并,比如a和b,合成数变成(a+b)/2,结果四舍五入.放在数组末尾,删除原来的a和b,举例子吧 就这样子两两合 ...

  8. 找出一个字符串中出现次数最多的字_海量数据中找出前k大数(topk问题)

    在海量数据中找出出现频率最好的前k个数,或者从海量数据中找出最大的前k个数,这类问题通常被称为top K问题. 针对top K类问题,通常比较好的方案是分治+Trie树/hash+小顶堆(就是上面提到 ...

  9. [菜鸟训练]347. 前 K 个高频元素

    题目描述: 给你一个整数数组 nums 和一个整数 k ,请你返回其中出现频率前 k 高的元素.你可以按 任意顺序 返回答案. 示例 1: 输入: nums = [1,1,1,2,2,3], k = ...

最新文章

  1. RANet : 分辨率自适应网络效果和性能的best trade-off | CVPR 2020
  2. ROC曲线与癌症分类
  3. 搜索页面scroll下拉时候进行刷新,显示更多搜索值
  4. json字符串与java对象的相互转换(jackson)
  5. STM32——流水灯
  6. linux目录及重要文件(持续更新)
  7. mysql 存储过程 行锁_mysql存储过程出现锁表锁行的情况怎么解决?如:
  8. 使用Python内置浏览器缓存cookies并做更新
  9. sun.misc.BASE64Encoder找不到的解决方法
  10. Node.js 教程第十四篇——Socket.io
  11. 【解决】Windows Mobile 6 Professional SDK Refresh.msi 在xp上一直卡死
  12. 使用src.rpm包安装软件
  13. 目前使用的python版本_Python版本到底有多少种?
  14. 如何清除matlab工作区,matlab命令窗口中可用什么命令清除工作区中的变量
  15. protues仿真出现Simulation is not running in real time....的情况处理
  16. 电信运营商移动互联网发展分析
  17. 【Linux】【操作】Linux操作集锦系列之三——进程管理系列之(一) 进程信息查看
  18. 局部线性嵌入(Locally Linear Embedding,简称LLE)
  19. 236767服务器网站,南京前三的FIL服务器网站
  20. java mysql 多表查询_Java编程基础32——MySQL多表联查

热门文章

  1. IOS基础之Foundation框架常用类NSFileManager,DSDate,CGPoint,CGSize,copy,单例
  2. MFC之实现鼠标自动左击,频率可调,支持热键
  3. python跳回循环开始位置_如何回到python中循环的开始?
  4. 一个按键控制数码管的开和关_基于FPGA的数字电路实验3:点亮数码管
  5. mysql-odbc的zip安装方法_win10环境下mysql-odbc的zip安装方法
  6. python列表生成器语法_python语法_列表生成器_生成器_迭代器_异常捕获
  7. Qt中的枚举变量,Q_ENUM,Q_FLAG,Q_NAMESPACE,Q_ENUM_NS,Q_FLAG_NS以及其他
  8. Error:Could not find appcompat-v7.aar (com.android.support:appcompat-v7:26.1.0). Searched in the fol
  9. git开发之查看修改账户邮箱命令
  10. linux bond 脚本,Linux--网卡聚合简单脚本(bond0)(示例代码)