Important Exam (贪心算法)

简介: Important Exam (贪心算法)

There are nn students in the class. The test had mm questions, each of them had 55 possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question ii worth aiai points. Incorrect answers are graded with zero points.


The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class.


Input


The first line contains integers nn and mm (1≤n,m≤1000) — the number of students in the class and the number of questions in the test.


Each of the next nn lines contains string sisi (|si|=m), describing an answer of the ii-th student. The jj-th character represents the student answer (A, B, C, D or E) on the jj-th question.


The last line contains mm integers a1,a2,…,am (1≤ai≤1000) — the number of points for the correct answer for every question.


Output


Print a single integer — the maximum possible total score of the class.


Examples


input

2 4

ABCD

ABCE

1 2 3 4


output

16


input

3 3

ABC

BCD

CDE

5 4 12


output

21


Note

In the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be 1616.


In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is 5+4+12=215+4+12=21.

题目,分析就是找每个答案出现最多的那个,然后把把次数最多的相乘,最后累加起来。


听懂了记得给个赞鼓励一下,码字不易,用爱发电。


上ac代码。

f58230e9f063709cf3167704f4efdf14.gif


有事你就q我;QQ2917366383


学习算法

    #include<iostream>
    #include<algorithm>
    #include<cstring>
    using namespace std;
    const int maxn=1e6+5;
    #define ll long long
  int maxm;
    int main()
    {
      int a[2005],b[6];
      string s[2005];
      int n,m,i=1,j;
        ll ans=0;
        cin>>n>>m;
      while(i<=n)
      {
        cin>>s[i];
        i++;
      }
      i=1;
      while(i<=m)
      {
        cin>>a[i];
        i++;
      }
      i=1;
      while(i<=m)
      {
        memset(b,0,sizeof(b));
        int maxm=-1;
        j=1;
        while(j<=n)
      {
        b[s[j][i-1]-'A'+1]++;
        j++;
       } 
       j=1;
       while(j<6)
       {
         maxm=max(maxm,b[j]);
       j++;
       }
      ans+=maxm*a[i];
      i++;
      }   
    cout<<ans<<endl;
      }
相关文章
|
资源调度 开发者
Vue2选择器(Select)
这是一个基于Vue3的选择器组件(VueAmazingSelector),已在npm上发布,方便快捷地通过`yarn add vue-amazing-selector`进行安装。此组件允许全局或局部注册,并提供了丰富的自定义属性,如选项数据、选择器文本字段名、值字段名、默认文字、禁用状态、清除功能等。同时,它还支持调整选择框的尺寸和下拉项数量,并附有详细的使用示例和代码片段,便于开发者快速集成和定制。
271 1
Vue2选择器(Select)
|
关系型数据库 MySQL 分布式数据库
ES如何做到亿级数据查询毫秒级返回
ES如何做到亿级数据查询毫秒级返回
232 0
|
7月前
|
存储 Cloud Native 关系型数据库
【赵渝强老师】TiDB的功能特性
TiDB是由PingCAP公司自主研发的开源分布式关系型数据库,支持HTAP(混合事务与分析处理),具备一键水平扩缩容、金融级高可用、实时HTAP、云原生架构及兼容MySQL协议等核心功能。其分布式设计可满足高可用、强一致性和大规模数据处理需求,适用于多种应用场景。视频讲解与详细功能介绍进一步展示了其技术优势和生态兼容性。
203 6
|
存储 Shell Linux
【Shell 命令集合 磁盘管理 】Linux 取消挂载 umount命令使用教程
【Shell 命令集合 磁盘管理 】Linux 取消挂载 umount命令使用教程
809 1
|
人工智能 算法 JavaScript
【算法】前缀和与差分
算法学习——前缀和与差分(含一维和二维)
179 4
【算法】前缀和与差分
|
存储 缓存 算法
Shiro【散列算法、Shiro会话、退出登录 、权限表设计、注解配置鉴权 】(五)-全面详解(学习总结---从入门到深化)(下)
Shiro【散列算法、Shiro会话、退出登录 、权限表设计、注解配置鉴权 】(五)-全面详解(学习总结---从入门到深化)
198 0
|
存储 持续交付
现代软件开发中的快速迭代与持续集成
在当今快节奏的软件开发环境中,快速迭代与持续集成成为关键。本文探讨了如何利用现代技术和工具,通过持续集成实现高效的软件开发和快速迭代,以及这些实践对开发团队和产品质量的积极影响。
356 3
|
前端开发 JavaScript 容器
早期 JavaScript 中的高阶函数与模块化实现
早期 JavaScript 中的高阶函数与模块化实现
|
监控 安全 Cloud Native
做ToB软件质量保障的这两年
本文出自一位 toB 业务的阿里老兵。希望能通过这篇文章,总结一下过往,并能和已经躬身进入这个业务领域,以及将要进入的同学们产生一些共鸣。
做ToB软件质量保障的这两年
|
消息中间件 SQL 存储
Presto on Apache Kafka 在 Uber 的大规模应用
本文最初发布于 Uber 官方博客,InfoQ 经授权翻译如下
327 0
Presto on Apache Kafka 在 Uber 的大规模应用