A12195 | Speed Dial
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Polycarp's phone book contains $n$ phone numbers, each of them is described by $s_i$ — the number itself and $m_i$ — the number of times Polycarp dials it in daily.
Polycarp has just bought a brand new phone with an amazing speed dial feature! More precisely, $k$ buttons on it can have a number assigned to it (not necessary from the phone book). To enter some number Polycarp can press one of these $k$ buttons and then finish the number using usual digit buttons (entering a number with only digit buttons is also possible).
Speed dial button can only be used when no digits are entered. No button can have its number reassigned.
What is the minimal total number of digit number presses Polycarp can achieve after he assigns numbers to speed dial buttons and enters each of the numbers from his phone book the given number of times in an optimal way?
Polycarp has just bought a brand new phone with an amazing speed dial feature! More precisely, $k$ buttons on it can have a number assigned to it (not necessary from the phone book). To enter some number Polycarp can press one of these $k$ buttons and then finish the number using usual digit buttons (entering a number with only digit buttons is also possible).
Speed dial button can only be used when no digits are entered. No button can have its number reassigned.
What is the minimal total number of digit number presses Polycarp can achieve after he assigns numbers to speed dial buttons and enters each of the numbers from his phone book the given number of times in an optimal way?
输入格式
The first line contains two integers $n$ and $k$ ( $1 \le n \le 500$ , $1 \le k \le 10$ ) — the amount of numbers in Polycarp's phone book and the number of speed dial buttons his new phone has.
The $i$ -th of the next $n$ lines contain a string $s_i$ and an integer $m_i$ $(1 \le m_i \le 500)$ , where $s_i$ is a non-empty string of digits from $0$ to $9$ inclusive (the $i$ -th number), and $m_i$ is the amount of times it will be dialed, respectively.
It is guaranteed that the total length of all phone numbers will not exceed $500$ .
The $i$ -th of the next $n$ lines contain a string $s_i$ and an integer $m_i$ $(1 \le m_i \le 500)$ , where $s_i$ is a non-empty string of digits from $0$ to $9$ inclusive (the $i$ -th number), and $m_i$ is the amount of times it will be dialed, respectively.
It is guaranteed that the total length of all phone numbers will not exceed $500$ .
输出格式
Print a single integer — the minimal total number of digit number presses Polycarp can achieve after he assigns numbers to speed dial buttons and enters each of the numbers from his phone book the given number of times in an optimal way.
输入输出样例
输入 #1
3 1 0001 5 001 4 01 1
输出 #1
14
输入 #2
3 1 0001 5 001 6 01 1
输出 #2
18
The only speed dial button in the first example should have "0001" on it. The total number of digit button presses will be $0 \cdot 5$ for the first number + $3 \cdot 4$ for the second + $2 \cdot 1$ for the third. $14$ in total.
The only speed dial button in the second example should have "00" on it. The total number of digit button presses will be $2 \cdot 5$ for the first number + $1 \cdot 6$ for the second + $2 \cdot 1$ for the third. $18$ in total.
The only speed dial button in the second example should have "00" on it. The total number of digit button presses will be $2 \cdot 5$ for the first number + $1 \cdot 6$ for the second + $2 \cdot 1$ for the third. $18$ in total.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted