#P13440. [GCJ 2009 #2] Crazy Rows
[GCJ 2009 #2] Crazy Rows
题目描述
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.
3
2
10
11
3
001
100
010
4
1110
1100
1100
1000
Case #1: 0
Case #2: 2
Case #3: 4
提示
Limits
Small dataset(6 Pts)
Large dataset(10 Pts)