A. Problem Generator

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Vlad is planning to hold m𝑚 rounds next month. Each round should contain one problem of difficulty levels 'A', 'B', 'C', 'D', 'E', 'F', and 'G'.

Vlad already has a bank of n𝑛 problems, where the i𝑖-th problem has a difficulty level of ai𝑎𝑖. There may not be enough of these problems, so he may have to come up with a few more problems.

Vlad wants to come up with as few problems as possible, so he asks you to find the minimum number of problems he needs to come up with in order to hold m𝑚 rounds.

For example, if m=1𝑚=1, n=10𝑛=10, a=𝑎= 'BGECDCBDED', then he needs to come up with two problems: one of difficulty level 'A' and one of difficulty level 'F'.

Input

The first line contains a single integer t𝑡 (1≤t≤10001≤𝑡≤1000) --- the number of test cases.

The first line of each test case contains two integers n𝑛 and m𝑚 (1≤n≤501≤𝑛≤50, 1≤m≤51≤𝑚≤5) --- the number of problems in the bank and the number of upcoming rounds, respectively.

The second line of each test case contains a string a𝑎 of n𝑛 characters from 'A' to 'G' --- the difficulties of the problems in the bank.

Output

For each test case, output a single integer --- the minimum number of problems that need to come up with to hold m𝑚 rounds.

Example

input

Copy

复制代码

3

10 1

BGECDCBDED

10 2

BGECDCBDED

9 1

BBCDEFFGG

output

Copy

复制代码
2
5
1

解题说明:此题是一道模拟器,因为每一轮都必须要出现A-G这几个字母,所以直接统计当前已出现的字母,然后判断每一轮中是否漏字母即可,最后求和。

cpp 复制代码
#include<stdio.h>

int main()
{
	int test;
	scanf("%d", &test);
	while (test--)
	{
		int a;
		int temp[7] = { 0 };
		int b;
		scanf("%d%d", &a, &b);
		char t[55];
		scanf(" %s", t);
		for (int i = 0; i < a; i++)
		{
			temp[t[i] - 65]++;
		}
		int count = 0;
		for (int i = 0; i < 7; i++)
		{
			if ((temp[i]) < b)
			{
				count += (b - (temp[i]));
			}
		}
		printf("%d\n", count);
	}
	return 0;
}
相关推荐
free-elcmacom几秒前
机器学习入门<4>RBFN算法详解
开发语言·人工智能·python·算法·机器学习
java修仙传8 分钟前
力扣hot100:最长连续序列
算法·leetcode·职场和发展
zore_c9 分钟前
【C语言】文件操作详解3(文件的随机读写和其他补充)
c语言·开发语言·数据结构·笔记·算法
Pluchon13 分钟前
硅基计划4.0 算法 记忆化搜索
java·数据结构·算法·leetcode·决策树·深度优先
CoderYanger13 分钟前
动态规划算法-简单多状态dp问题:18.买卖股票的最佳时机Ⅳ
开发语言·算法·leetcode·动态规划·1024程序员节
Less is moree15 分钟前
2.C语言文件操作(一):fgetc(),fgets(),fread的区别
c语言·开发语言·算法
CoderYanger16 分钟前
动态规划算法-简单多状态dp问题:13.删除并获得点数
java·开发语言·数据结构·算法·leetcode·动态规划·1024程序员节
浅川.2518 分钟前
xtuoj Balls
数据结构·算法
分布式存储与RustFS18 分钟前
云原生基石:实战RustFS on Kubernetes,构建高可用存储架构
算法·云原生·kubernetes·对象存储·高可用·企业存储·rustfs
顾人间讥诘22 分钟前
卡特兰数及相关应用场景
算法