A8427 | Garden
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Vasya has a very beautiful country garden that can be represented as an $n×m$ rectangular field divided into $n·m$ squares. One beautiful day Vasya remembered that he needs to pave roads between $k$ important squares that contain buildings. To pave a road, he can cover some squares of his garden with concrete.
For each garden square we know number $a_{i}_{j}$ that represents the number of flowers that grow in the square with coordinates $(i,j)$ . When a square is covered with concrete, all flowers that grow in the square die.
Vasya wants to cover some squares with concrete so that the following conditions were fulfilled:
- all $k$ important squares should necessarily be covered with concrete
- from each important square there should be a way to any other important square. The way should go be paved with concrete-covered squares considering that neighboring squares are squares that have a common side
- the total number of dead plants should be minimum
As Vasya has a rather large garden, he asks you to help him.
For each garden square we know number $a_{i}_{j}$ that represents the number of flowers that grow in the square with coordinates $(i,j)$ . When a square is covered with concrete, all flowers that grow in the square die.
Vasya wants to cover some squares with concrete so that the following conditions were fulfilled:
- all $k$ important squares should necessarily be covered with concrete
- from each important square there should be a way to any other important square. The way should go be paved with concrete-covered squares considering that neighboring squares are squares that have a common side
- the total number of dead plants should be minimum
As Vasya has a rather large garden, he asks you to help him.
输入格式
The first input line contains three integers $n$ , $m$ and $k$ ( $1<=n,m<=100$ , $n·m<=200$ , $1<=k<=min(n·m,7$ )) — the garden's sizes and the number of the important squares. Each of the next $n$ lines contains $m$ numbers $a_{i}_{j}$ ( $1<=a_{i}_{j}<=1000$ ) — the numbers of flowers in the squares. Next $k$ lines contain coordinates of important squares written as " $x$ $y$ " (without quotes) ( $1<=x<=n$ , $1<=y<=m$ ). The numbers written on one line are separated by spaces. It is guaranteed that all $k$ important squares have different coordinates.
输出格式
In the first line print the single integer — the minimum number of plants that die during the road construction. Then print $n$ lines each containing $m$ characters — the garden's plan. In this plan use character "X" (uppercase Latin letter X) to represent a concrete-covered square and use character "." (dot) for a square that isn't covered with concrete. If there are multiple solutions, print any of them.
输入输出样例
输入 #1
3 3 2 1 2 3 1 2 3 1 2 3 1 2 3 3
输出 #1
9 .X. .X. .XX
输入 #2
4 5 4 1 4 5 1 2 2 2 2 2 7 2 4 1 4 5 3 2 1 7 1 1 1 1 5 4 1 4 4
输出 #2
26 X..XX XXXX. X.X.. X.XX.
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted