logo AlgoBeat OnlineJudge
登录 注册

#213565. [GCJ 2009 #2] Crazy Rows

内存限制:1024 MiB 时间限制:3000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

You are given an matrix with and values. You can swap any two adjacent rows of the matrix.

Your goal is to have all the values in the matrix below or on the main diagonal. That is, for each where , there must be no values in row that are to the right of column .

Return the minimum number of row swaps you need to achieve the goal.

输入格式

The first line of input gives the number of cases, . test cases follow.

The first line of each test case has one integer, . Each of the next lines contains characters. Each character is either or .

输出格式

For each test case, output

Case #X: K

where is the test case number, starting from , and is the minimum number of row swaps needed to have all the values in the matrix below or on the main diagonal.

You are guaranteed that there is a solution for each test case.

样例

样例输入 1

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

样例输出 1

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

数据范围与提示

Limits

Small dataset(6 Pts)

Large dataset(10 Pts)