QOJ.ac

QOJ

時間限制: 2.0 s 記憶體限制: 1024 MB 總分: 100

#10019. 金币

统计

考虑一个包含 $r$ 行 $c$ 列的网格的盒子,行编号从 $1$ 到 $r$,列编号从 $1$ 到 $c$。网格中的每个方格要么是空的,要么包含一枚金币。

盒子的状态由一个二维二进制矩阵 $s$ 表示。如果第 $x$ 行第 $y$ 列的单元格为空,则 $s_{x,y}$ 的值为 $0$;如果该单元格包含一枚金币,则 $s_{x,y}$ 的值为 $1$。

考虑以下区分金币的方法: 令 $a_{x,y}$ 为满足 $i = x$ 且 $1 \le j \le y$ 的所有整数对 $(i, j)$ 的 $s_{i,j}$ 之和。 令 $b_{x,y}$ 为满足 $1 \le i \le x$ 且 $j = y$ 的所有整数对 $(i, j)$ 的 $s_{i,j}$ 之和。 * 如果第 $x$ 行第 $y$ 列的单元格包含一枚金币,则用二元组 $(a_{x,y}, b_{x,y})$ 标记该金币。

这种方法可能导致多枚金币具有相同的标签,从而无法区分这些金币。因此,我们可以在标记金币之前添加一些金币。更正式地说,我们可以执行零次或多次以下操作:选择一个满足 $s_{x,y} = 0$ 的位置 $(x, y)$,并将 $s_{x,y}$ 设置为 $1$。

请问为了使没有任何两枚金币具有相同的标签,最少需要添加多少枚金币?

输入格式

第一行包含两个整数:$r$ 和 $c$ ($1 \le r, c \le 300$)。接下来的 $r$ 行中,每行包含 $c$ 个整数 $s_{i,j}$。其中第 $i$ 行的第 $j$ 个整数表示初始时 $s_{i,j}$ 是否有金币,若无则为 $0$,若有则为 $1$。

输出格式

输出一个整数:为了使所有金币的标签各不相同,最少需要添加的金币数量。

样例

输入 1

2 3
1 0 0
0 1 1

输出 1

1

输入 2

4 4
0 1 1 1
1 1 0 0
1 1 1 1
1 0 1 0

输出 2

2

输入 3

7 7
0 0 0 0 0 0 0
0 1 0 1 0 1 0
1 0 1 0 1 0 1
0 1 0 1 0 1 0
1 0 1 0 1 0 1
0 1 0 1 0 1 0
1 0 1 0 1 0 1

输出 3

18

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1792EditorialOpenNew Editorial for Problem #10019lzlqwq2026-05-22 12:01:04View

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.