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算法的思想很相似(可能出题人就是照着改编的).当 ...
随机推荐
- jquery取得iframe中元素的方法
原文发布时间为:2010-12-27 -- 来源于本人的百度文章 [由搬家工具导入] 收集利用Jquery取得iframe中元素的几种方法 :contents() $.trim($("if ...
- dedeCMS php标签使用说明和数据库查询说明
1.{dede:php}标签想要输出信息 可以直接使用printf , echo,var_dump 之类的打印出来 赋值给@me 无效 2.结合sql语句使用方法 例:{dede:php} $ro ...
- linux下的用户组管理
用户组管理分两类 如果赋给组什么权限,那么组员就会有什么权限 1.私有组 在创建新用户的时候,就要为用户指定组.如果没有指定,就会默认创建一个与用户名相同的用户组,这个用户组只有该用户一个用户,就被称 ...
- 关于apache 虚拟主机配置访问403的问题
<Directory /> Options FollowSymLinks Order allow,deny Allow from all</Directory&g ...
- myeclipse服务器"未能创建视图:抛出意外异常。"
找到对应目录 Workspaces\.metadata\.plugins\org.eclipse.core.runtime\.settings 下的 com.genuitec.eclipse.ast. ...
- 多线程设计模式 : Master-Worker模式
Master-Worker是常用的并行计算模式.它的核心思想是系统由两类进程协作工作:Master进程和Worker进程.Master负责接收和分配任务,Worker负责处理子任务.当各个Worker ...
- Mysql varchar长度问题
http://dinglin.iteye.com/blog/914276 http://www.cnblogs.com/fakis/archive/2011/03/07/1976532.html ...
- FZU 1056 扫雷游戏【搜索】
Accept: 2584 Submit: 6790Time Limit: 1000 mSec Memory Limit : 32768 KB Problem Description 扫雷是 ...
- 10.1综合强化刷题 Day1 afternoon
一道图论好题(graph) Time Limit:1000ms Memory Limit:128MB 题目描述 LYK有一张无向图G={V,E},这张无向图有n个点m条边组成.并且这是一张带权图, ...
- NOI模拟题5 Problem A: 开场题
Solution 注意到\(\gcd\)具有结合律: \[ \gcd(a, b, c) = \gcd(a, \gcd(b, c)) \] 因此我们从后往前, 对于每个位置\(L\), 找到每一段不同的 ...