CF543C.Remembering Strings

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You have multiset of n 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 i and some letter c of the English alphabet, such that this string is the only string in the multiset that has letter c in position i.

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 c in position 3;
  • the second string is the only string that has character d in position 2;
  • the third string is the only string that has character s in position 2.

You want to change your multiset a little so that it is easy to remember. For a__ij coins, you can change character in the j-th position of the i-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.

你有一个由 nn 个多重集(multiset)字符串组成的集合,每个字符串长度相同,且仅由小写英文字母组成。我们称该字符串多重集是“易于记忆的”,当且仅当对其中每一个字符串,都存在某个位置 ii 和某个英文字母 cc,使得该字符串是整个多重集中唯一一个在第 ii 个位置上含有字母 cc 的字符串。

例如,字符串多重集 {"abc","aba","adc","ada"}\{"abc", "aba", "adc", "ada"\} 不是易于记忆的;而多重集 {"abc","ada","ssa"}\{"abc", "ada", "ssa"\} 是易于记忆的,因为:

  • 第一个字符串是唯一一个在位置 3 上含有字符 cc 的字符串;
  • 第二个字符串是唯一一个在位置 2 上含有字符 dd 的字符串;
  • 第三个字符串是唯一一个在位置 2 上含有字符 ss 的字符串。

你想对这个多重集稍作修改,使其变为易于记忆的。你可以花费 aija_{ij} 枚硬币,将第 ii 个字符串的第 jj 个位置上的字符修改为任意其他小写英文字母。求使该字符串多重集变得易于记忆所需支付的最小总费用。

输入格式

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

Next n lines contain m integers each, the i-th of them contains integers _a__i_1, _a__i_2, ..., a__im (0 ≤ a__ij ≤ 106).

第一行包含两个整数 nn、mm(1≤n,m≤201 \leq n, m \leq 20)—— 分别表示多重集中的字符串数量和每个字符串的长度。接下来的 nn 行包含该多重集中的字符串,每个字符串仅由小写英文字母组成,且长度均为 mm。

接下来的 nn 行每行包含 mm 个整数,其中第 ii 行包含整数 ai1, ai2, …, aima_{i1},\ a_{i2},\ \dots,\ a_{im}(0≤aij≤1060 \leq a_{ij} \leq 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

输入解题思路,AI测评打分。不知道怎么写?

首页