K개의 장애물이 있는 N x N 보드에서 두 룩이 같은 줄에 있더라도 사이에 장애물이 없으면 공격하지 못하도록 최대 개수의 룩을 배치한다.
어려움8그래프조합론동적 계획법그리디아직 제출이 없습니다시간 제한0.4초메모리 제한1024 MBConsider a square board with N rows (called ranks) and N columns (called files). K of the squares are blocked by obstacles. Pieces similar to the rooks in chess are placed on this board. Two rooks are said to be attacking each other if they are on the same rank or file and there are no obstacles between them.
Given a positive integer N and the positions of the K obstacles, place as many rooks as possible on the board so that no two rooks attack each other.
The first line of the input contains N and K, separated by a space. Each of the following K lines contain a pair of numbers r and f, separated by a space describing the rank and file of an obstacle. All the obstacles are distinct.
The first line of the output must contain a single number S, the highest number of non-attacking rooks that the table can accommodate. Each of the following S lines must contain a pair of numbers r and f, separated by a space, showing the rank and file of a rook. Any correct placement of S rooks will be accepted.