欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1359B.New Theatre Square
New Theatre Square
You might have remembered Theatre square from the problem 1A. Now it's finally getting repaved.
The square still has a rectangular shape of meters. However, the picture is about to get more complicated now. Let be the -th square in the -th row of the pavement.
You are given the picture of the squares:
- if "
\*", then the -th square in the -th row should be black; - if "
.", then the -th square in the -th row should be white.
The black squares are paved already. You have to pave the white squares. There are two options for pavement tiles:
- tiles — each tile costs burles and covers exactly square;
- tiles — each tile costs burles and covers exactly adjacent squares of the same row. Note that you are not allowed to rotate these tiles or cut them into tiles.
You should cover all the white squares, no two tiles should overlap and no black squares should be covered by tiles.
What is the smallest total price of the tiles needed to cover all the white squares?
Input
The first line contains a single integer () — the number of testcases. Then the description of testcases follow.
The first line of each testcase contains four integers , , and (; ; ) — the size of the Theatre square, the price of the tile and the price of the tile.
Each of the next lines contains characters. The -th character in the -th line is . If "\*", then the -th square in the -th row should be black, and if ".", then the -th square in the -th row should be white.
It's guaranteed that the sum of over all testcases doesn't exceed .
Output
For each testcase print a single integer — the smallest total price of the tiles needed to cover all the white squares in burles.
Note
In the first testcase you are required to use a single tile, even though tile is cheaper. So the total price is burles.
In the second testcase you can either use two tiles and spend burles or use a single tile and spend burle. The second option is cheaper, thus the answer is .
The third testcase shows that you can't rotate tiles. You still have to use two tiles for the total price of .
In the fourth testcase the cheapest way is to use tiles everywhere. The total cost is .
Samples
4
1 1 10 1
.
1 2 10 1
..
2 1 10 1
.
.
3 3 3 7
..*
*..
.*.
10
1
20
18
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |