A9949 | Remembering Strings
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
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_{i1},a_{i2},...,a_{im}$ ( $0<=a_{ij}<=10^{6}$ ).
Next $n$ lines contain $m$ integers each, the $i$ -th of them contains integers $a_{i1},a_{i2},...,a_{im}$ ( $0<=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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted