QOJ.ac

QOJ

时间限制: 4 s 内存限制: 1024 MB 总分: 16

#5800. 疯狂的行

统计

给定一个 $N \times N$ 的矩阵,其中包含 0 和 1。你可以交换矩阵中任意两行相邻的行。

你的目标是使矩阵中所有的 1 都位于主对角线及其下方。也就是说,对于每个 $1 \le X \le N$,第 $X$ 行中不应有任何 1 位于第 $X$ 列的右侧。

返回实现该目标所需的最少行交换次数。

输入格式

输入的第一行包含测试用例的数量 $T$。接下来是 $T$ 个测试用例。

每个测试用例的第一行包含一个整数 $N$。接下来的 $N$ 行,每行包含 $N$ 个字符,每个字符为 0 或 1。

输出格式

对于每个测试用例,输出:

Case #X: K

其中 $X$ 是测试用例编号(从 1 开始),$K$ 是使矩阵中所有 1 都位于主对角线及其下方所需的最少行交换次数。

题目保证每个测试用例都有解。

样例

输入格式 1

3
2
10
11
3
001
100
010
4
1110
1100
1100
1000

输出格式 1

Case #1: 0
Case #2: 2
Case #3: 4

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.