Codeforces Round #263 (Div. 2) proB
题目:
1 second
256 megabytes
standard input
standard output
Appleman has n cards. Each card has an uppercase letter written on it. Toastman must choose k cards
from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally, for each Toastman's card i you should calculate
how much Toastman's cards have the letter equal to letter on ith, then sum up all these quantities, such a number of coins Appleman should give to Toastman.
Given the description of Appleman's cards. What is the maximum number of coins Toastman can get?
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 105).
The next line contains n uppercase letters without spaces — the i-th
letter describes the i-th card of the Appleman.
Print a single integer – the answer to the problem.
15 10
DZFDFZDFDDDDDDF
82
6 4
YJSNPI
4
In the first test example Toastman can choose nine cards with letter D and one additional card with any letter. For each card with D he
will get 9 coins and for the additional card he will get 1 coin.
题意分析:
能够得的分数是卡数的平分,求最大分数。
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char s[110000];
int j[500],cn[500];
void solve()
{
int n,k;
long long ans=0;
scanf("%d%d",&n,&k);
scanf("%s",s);
int len=strlen(s);
for(int i=0; i<len; i++)
{
j[s[i]]++;
}
while(k)
{
k--;
int w=0,Max=0;
for(int i='A'; i<='Z'; i++)
{
if(j[i]>Max&&cn[i]<j[i])
{
Max=j[i];
w=i;
}
}
cn[w]++;
}
for(int i='A'; i<='Z'; i++)
{
ans+=1LL*cn[i]*cn[i];
}
cout<<ans<<endl;
}
int main()
{
solve();
return 0;
}
Codeforces Round #263 (Div. 2) proB的更多相关文章
- 贪心 Codeforces Round #263 (Div. 2) C. Appleman and Toastman
题目传送门 /* 贪心:每次把一个丢掉,选择最小的.累加求和,重复n-1次 */ /************************************************ Author :R ...
- Codeforces Round #263 (Div. 2)
吐槽:一辈子要在DIV 2混了. A,B,C都是简单题,看AC人数就知道了. A:如果我们定义数组为N*N的话就不用考虑边界了 #include<iostream> #include &l ...
- Codeforces Round #263 (Div. 1)
B 树形dp 组合的思想. Z队长的思路. dp[i][1]表示以i为跟结点的子树向上贡献1个的方案,dp[i][0]表示以i为跟结点的子树向上贡献0个的方案. 如果当前为叶子节点,dp[i][0] ...
- Codeforces Round #263 Div.1 B Appleman and Tree --树形DP【转】
题意:给了一棵树以及每个节点的颜色,1代表黑,0代表白,求将这棵树拆成k棵树,使得每棵树恰好有一个黑色节点的方法数 解法:树形DP问题.定义: dp[u][0]表示以u为根的子树对父亲的贡献为0 dp ...
- Codeforces Round #263 (Div. 2) D. Appleman and Tree(树形DP)
题目链接 D. Appleman and Tree time limit per test :2 seconds memory limit per test: 256 megabytes input ...
- Codeforces Round #263 (Div. 2) A B C
题目链接 A. Appleman and Easy Task time limit per test:2 secondsmemory limit per test:256 megabytesinput ...
- Codeforces Round #263 (Div. 1) C. Appleman and a Sheet of Paper 树状数组暴力更新
C. Appleman and a Sheet of Paper Appleman has a very big sheet of paper. This sheet has a form of ...
- Codeforces Round #263 (Div. 2) proC
题目: C. Appleman and Toastman time limit per test 2 seconds memory limit per test 256 megabytes input ...
- Codeforces Round #263 (Div. 2)C(贪心,联想到huffman算法)
数学家伯利亚在<怎样解题>里说过的解题步骤第二步就是迅速想到与该题有关的原型题.(积累的重要性!) 对于这道题,可以发现其实和huffman算法的思想很相似(可能出题人就是照着改编的).当 ...
随机推荐
- vue 简易toDoList
vue+bootstrap简易响应式任务管理表: <!DOCTYPE html> <html> <head> <meta charset="UTF- ...
- libc++abi.dylib`__cxa_throw: 使用[AVAudioPlayer play]会产生__cxa_throw异常
libc++abi.dylib`__cxa_throw: 使用[AVAudioPlayer play]会产生__cxa_throw异常 开发中遇到一个奇怪的异常.我调用AVAudioPlayer pl ...
- 【HDOJ5510】Bazinga(KMP)
题意:给定n个由小写字母组成的字符串,第i个字符串为a[i],求最大的j满足存在1<=i<j,a[i]不是a[j]的子串,无解输出-1 T<=50,n<=500,len[i]& ...
- Javascript的SEO优化技巧
原文发布时间为:2010-10-22 -- 来源于本人的百度文章 [由搬家工具导入] 1.外部崁入javascript在撰写一些比较复杂的网页特效,如下拉式选单等,会产生大量的javascript码, ...
- Use ASP.NET and DotNetZip to Create and Extract ZIP Files
原文发布时间为:2011-02-16 -- 来源于本人的百度文章 [由搬家工具导入] Published: 11 Feb 2011By: Scott MitchellDownload Sample C ...
- 用正则表达式模仿Mustache插件的功能
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...
- luogu 3407 散步
题目链接 题意 按从左到右的顺序给出数轴上的一群人,有人向左走,有人向右走,一旦两人相遇就会停在当前位置,后来走到该位置的人也会停在该位置.问经过一段时间这些人分别在什么位置. 思路 可以将这些人分为 ...
- 【Visual Studio】“rc.exe”已退出,代码为 5 ("rc.exe" exited with code 5.)
[解决方案]找到 rc.exe 所在目录,然后 方法1:添加该目录到 VC++ Directories --> Executable Directories中 方法2:添加到系统变量中的Path ...
- TCMalloc小记【转】
转自:http://blog.csdn.net/chosen0ne/article/details/9338591 版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[-] 一 原理 二 ...
- 安装glibc错误链接导致系统崩溃,u盘启动紧急救援模式下修复系统。
Sln 命令 创建动态符号链接 用法 sln source dest 故障案例:一个误操作 导致了一个不小的故障,输入所有命令都无效,直接系统无法启动. 故障描述 sln /usr/lib64/l ...