I saw this programming puzzle on a website and tried to solve it.
PROBLEM
You are given an N x N grid in which there are certain points randomly distributed. You must delete the points using the following valid steps.
You can either delete all points in the row with one shot.
Or you can delete all points in a column with one shot.
You should find the minimum number of shots needed to delete all points.
Example
In the next grid, you need three shots: one horizontal and two vertical to remove points.
, , , . , . - , , ?
:
1 <= N <= 1000 0 <= x,y <= 10^9 Time Limit: 2 sec
n - (.. nxn) x, y -
. , , , . , , , (x, y), , row_x column_y. . , , .
O (V * E). .
, pls , , .
. , , .
, N ( , ).
, , + , N. , N = 4, be <= 3, (, ) :
(0,3) (1,2) (2,1) (3,0)
( ), s-, (s choose N). , N - (N/2) choose N, N < 30 .
(s choose N)
(N/2) choose N
, , .
, . , , - , .
- . :
. β
, . β , .
, .- > , .
. β , .
1- :
int minimumNumberOfLines( matrixOfDots ) { return min( 1 + minimumNumberOfLines( with row shot ),1 + minimumNumberOfLines( with col shot ), 2 + minimumNumberOfLines( with row and column shot ) ). }