CF903F.Clear The Matrix

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given a matrix f with 4 rows and n columns. Each element of the matrix is either an asterisk (*) or a dot (.).

You may perform the following operation arbitrary number of times: choose a square submatrix of f with size k × k (where 1 ≤ k ≤ 4) and replace each element of the chosen submatrix with a dot. Choosing a submatrix of size k × k costs a__k coins.

What is the minimum number of coins you have to pay to replace all asterisks with dots?

你被给定一个包含 4 行和 $ n $ 列的矩阵 $ f $。矩阵中的每个元素要么是星号(*),要么是点号(.)。

你可以执行以下操作任意多次:选择矩阵 $ f $ 中一个大小为 $ k \times k $ 的正方形子矩阵(其中 $ 1 \leq k \leq 4 $),并将该子矩阵中的每个元素替换为点号(.)。选择一个大小为 $ k \times k $ 的子矩阵需要花费 $ a_k $ 枚金币。

将所有星号(*)替换为点号(.)所需的最少金币数是多少?

输入格式

The first line contains one integer n (4 ≤ n ≤ 1000) — the number of columns in f.

The second line contains 4 integers _a_1, _a_2, _a_3, _a_4 (1 ≤ a__i ≤ 1000) — the cost to replace the square submatrix of size 1 × 1, 2 × 2, 3 × 3 or 4 × 4, respectively.

Then four lines follow, each containing n characters and denoting a row of matrix f. Each character is either a dot or an asterisk.

第一行包含一个整数 nn(4≤n≤10004 \leq n \leq 1000)—— 表示矩阵 ff 的列数。

第二行包含 4 个整数 a1,a2,a3,a4a_1, a_2, a_3, a_4(1≤ai≤10001 \leq a_i \leq 1000)—— 分别表示替换大小为 1×11 \times 1、2×22 \times 2、3×33 \times 3 或 4×44 \times 4 的正方形子矩阵的代价。

接下来是四行,每行包含 nn 个字符,表示矩阵 ff 的一行。每个字符要么是英文句点(.),要么是星号(*)。

输出格式

Print one integer — the minimum number of coins to replace all asterisks with dots.

输出一个整数——将所有星号(*)替换为点号(.)所需的最少硬币数量。

输入输出样例

  • 输入#1

    4
    1 10 8 20
    ***.
    ***.
    ***.
    ...*

    输出#1

    9
  • 输入#2

    7
    2 1 8 2
    .***...
    .***..*
    .***...
    ....*..

    输出#2

    3
  • 输入#3

    4
    10 10 1 10
    ***.
    *..*
    *..*
    .***

    输出#3

    2

说明/提示

In the first example you can spend 8 coins to replace the submatrix 3 × 3 in the top-left corner, and 1 coin to replace the 1 × 1 submatrix in the bottom-right corner.

In the second example the best option is to replace the 4 × 4 submatrix containing columns 2 – 5, and the 2 × 2 submatrix consisting of rows 2 – 3 and columns 6 – 7.

In the third example you can select submatrix 3 × 3 in the top-left corner and then submatrix 3 × 3 consisting of rows 2 – 4 and columns 2 – 4.

在第一个例子中,你可以花费 8 枚硬币替换左上角的 3×33 \times 3 子矩阵,再花费 1 枚硬币替换右下角的 1×11 \times 1 子矩阵。

在第二个例子中,最优方案是替换包含第 2–5 列的 4×44 \times 4 子矩阵,以及由第 2–3 行和第 6–7 列构成的 2×22 \times 2 子矩阵。

在第三个例子中,你可以先选择左上角的 3×33 \times 3 子矩阵,再选择由第 2–4 行和第 2–4 列构成的 3×33 \times 3 子矩阵。

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

首页