As far as I understand,  it says "1 values should be below or on the
diagonal",  (*)
so we can do the following:

1)
1110
1100
1100
1000

2)
1110
1100
1000
1100
(ie R3 <-> R4)

3)
1100
1110
1000
1100
(R1 <-> R2)

4)
1100
1000
1110
1100
(R2 <-> R3)

5)
1000
1100
1110
1100
(R1 <-> R2)

Note that the final output satisfies (*)

And hence 4 steps.




2012/4/9 Minseok Jang <[email protected]>

> in round2, 2009 problem A.Crazy Rows
>
>
> ----------------------------------------------------------------------------------------
>
> Problem
>
> You are given an *N* x *N* matrix with 0 and 1 values. You can swap any
> two *adjacent* rows of the matrix.
>
> Your goal is to have all the 1 values in the matrix below or on the main
> diagonal. That is, for each X where 1 ≤ X ≤ N, there must be no 1 values in
> row X that are to the right of column X.
>
> Return the minimum number of row swaps you need to achieve the goal.
>
> Input
>
> The first line of input gives the number of cases, *T*. *T* test cases
> follow.
> The first line of each test case has one integer, *N*. Each of the next *N
> * lines contains *N* characters. Each character is either 0 or 1.
>
> Output
>
> For each test case, output
>
> Case #X: K
>
> where *X* is the test case number, starting from 1, and *K* is the
> minimum number of row swaps needed to have all the 1 values in the matrix
> below or on the main diagonal.
>
> You are guaranteed that there is a solution for each test case.
>
>
> -----------------------------------------------------------------------------------------------
>
>
>
> my question is in sample in/out
>
> input
>
> 1110
> 1100
> 1100
> 1000
>
> output # 4
>
> how can output get the "4"
>
> isn't it five??
>
> please , someone let me know each step for that
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Code Jam" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-code?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-code?hl=en.

Reply via email to