CF543C.Remembering Strings

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You have multiset of nn strings of the same length, consisting of lowercase English letters. We will say that those strings are easy to remember if for each string there is some position ii and some letter cc of the English alphabet, such that this string is the only string in the multiset that has letter cc in position ii .

For example, a multiset of strings {"abc", "aba", "adc", "ada"} are not easy to remember. And multiset {"abc", "ada", "ssa"} is easy to remember because:

  • the first string is the only string that has character cc in position 33 ;
  • the second string is the only string that has character dd in position 22 ;
  • the third string is the only string that has character ss in position 22 .

You want to change your multiset a little so that it is easy to remember. For aija_{ij} coins, you can change character in the jj -th position of the ii -th string into any other lowercase letter of the English alphabet. Find what is the minimum sum you should pay in order to make the multiset of strings easy to remember.

输入格式

The first line contains two integers nn , mm ( 1<=n,m<=201<=n,m<=20 ) — the number of strings in the multiset and the length of the strings respectively. Next nn lines contain the strings of the multiset, consisting only of lowercase English letters, each string's length is mm .

Next nn lines contain mm integers each, the ii -th of them contains integers ai1,ai2,...,aima_{i1},a_{i2},...,a_{im} ( 0<=aij<=1060<=a_{ij}<=10^{6} ).

输出格式

Print a single number — the answer to the problem.

输入输出样例

  • 输入#1

    4 5
    abcde
    abcde
    abcde
    abcde
    1 1 1 1 1
    1 1 1 1 1
    1 1 1 1 1
    1 1 1 1 1
    

    输出#1

    3
    
  • 输入#2

    4 3
    abc
    aba
    adc
    ada
    10 10 10
    10 1 10
    10 10 10
    10 1 10
    

    输出#2

    2
    
  • 输入#3

    3 3
    abc
    ada
    ssa
    1 1 1
    1 1 1
    1 1 1
    

    输出#3

    0
    
首页