TopCoder

User's AC Ratio

NaN% (0/0)

Submission's AC Ratio

NaN% (0/0)

Tags

Description

Down town BigCity is covered by a grid of n East-West avenues (numbered from 1 to n) intersecting
with n North-South streets (numbered from 1 to n). At the intersection between an avenue and a street,
there is a light post. At each avenue or street, there is a power switch which turns on all n lights along that
avenue/street. At day time, all the lights are automatically turned off. Every evening, due to security
reasons, the lights at a certain number of intersections must be turned on. To minimize the effort to turn on
the required lights, they wish to use the smallest number of power switches.

Your goal is to write a program that computes the smallest number of power switches that must be used
to turn on the required lights.

Input Format

The input file consists of several data sets. The first line of the input file contains the number of data
sets which is a positive integer and is not bigger than 200. The following lines describe the data sets.

For each data set, the first line contains an integer n (1 ≤ n ≤ 30). Next n lines (each of which contains n
binary digits separated by space) contains a matrix R of size n×n representing the requirements about the
lights which need to be turned on. The value 1 of R(i,j) means that the light at the intersection between ith
avenue and jth street must be turned on. The value 0 of R(i,j) means that there is no requirement for the
light at the intersection between ith avenue and jth street.

Output Format

For each data set, write in one line an integer representing the smallest number of power switches that
must be turned on.

Sample Input 1

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

Sample Output 1

5

Hints

Problem Source

Migrated from old NTUJ.

The ACM-ICPC 2010 Asia Regional Contest, Site Hanoi

Subtasks

No. Testdata Range Score

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 1000 65536 200