A8164 | Sequence of Balls
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given a sequence of balls $A$ by your teacher, each labeled with a lowercase Latin letter 'a'-'z'. You don't like the given sequence. You want to change it into a new sequence, $B$ that suits you better. So, you allow yourself four operations:
- You can insert any ball with any label into the sequence at any position.
- You can delete (remove) any ball from any position.
- You can replace any ball with any other ball.
- You can exchange (swap) two adjacent balls.
Your teacher now places time constraints on each operation, meaning that an operation can only be performed in certain time. So, the first operation takes time $t_{i}$ , the second one takes $t_{d}$ , the third one takes $t_{r}$ and the fourth one takes $t_{e}$ . Also, it is given that $2·t_{e}>=t_{i}+t_{d}$ .
Find the minimal time to convert the sequence $A$ to the sequence $B$ .
- You can insert any ball with any label into the sequence at any position.
- You can delete (remove) any ball from any position.
- You can replace any ball with any other ball.
- You can exchange (swap) two adjacent balls.
Your teacher now places time constraints on each operation, meaning that an operation can only be performed in certain time. So, the first operation takes time $t_{i}$ , the second one takes $t_{d}$ , the third one takes $t_{r}$ and the fourth one takes $t_{e}$ . Also, it is given that $2·t_{e}>=t_{i}+t_{d}$ .
Find the minimal time to convert the sequence $A$ to the sequence $B$ .
输入格式
The first line contains four space-separated integers $t_{i},t_{d},t_{r},t_{e}$ ( $0<t_{i},t_{d},t_{r},t_{e}<=100$ ). The following two lines contain sequences $A$ and $B$ on separate lines. The length of each line is between 1 and 4000 characters inclusive.
输出格式
Print a single integer representing minimum time to convert $A$ into $B$ .
输入输出样例
输入 #1
1 1 1 1 youshouldnot thoushaltnot
输出 #1
5
输入 #2
2 4 10 3 ab ba
输出 #2
3
输入 #3
1 10 20 30 a za
输出 #3
1
In the second sample, you could delete the ball labeled 'a' from the first position and then insert another 'a' at the new second position with total time 6. However exchanging the balls give total time 3.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted