Hnu13028attacking rooks (two-point match, one row is changed to multiple rows, and one column is changed to multiple columns)

Source: Internet
Author: User
Attacking Rooks
Time limit:20000 ms,Special time limit:50000 ms,Memory limit:65536kb
Total submit users:12,Accepted users:7
Problem 13028:No special judgement
Problem description
Chess has red problems are a common source of exercises in algorithms classes. starting with the well known 8-queens problem, several generalizations and variations were made. one of them is the n-Rooks problem, which consists of placing n rooks in an N by N chessboard in such a way that they do not attack each other.
Using sor Anand presented the n-Rooks problem to his students. since Rooks only attack each other when they share a row or column, they soon discovered that the problem can be easily solved by placing the Rooks along a main diagonal of the Board. so, the cipher sor decided to complicate the problem by adding some pawns to the board. in a board with pawns, two Rooks attack each other if and only if they share a row or column and there is no pawn placed between them. besides, pawns occupy some squares, which gives an additional restriction on which squares the Rooks may be placed on.
Given the size of the Board and the location of the pawns, tell should sor Anand the maximum number of rooks that can be placed on empty squares such that no two of them attack each other.

Input
The first line contains an integer N (1 ≤ n ≤100) representing the number of rows and columns of the Board. each of the next n lines contains a string of n characters. in the I-th of these strings, the J-th character represents the square in the I-th row and J-th Column of the Board. the character is either ". "(DOT) or the uppercase letter" X ", indicating respectively an empty square or a square containing a pawn.
Output
Output a line with an integer representing the maximum number of rooks that can be placed on the empty squares of the Board without attacking each other.
Sample Input
Sample input 15X....X......X...X.......XSample input 24.....X..........Sample input 31X
Sample output
Sample output 17Sample output 25Sample output 30
Problem Source
ICPC Latin American Regional 2013
# Include <stdio. h> # include <iostream> # include <string. h ># include <vector> using namespace STD; vector <int> map [10005]; int match [10005], vist [10005]; int find (int x) {int Len = map [X]. size (); For (INT I = 0; I <Len; I ++) if (vist [map [x] [I] = 0) {vist [map [x] [I] = 1; if (Match [map [x] [I] = 0 | find (Match [map [x] [I]) {match [map [x] [I] = x; return 1 ;}} return 0 ;}int main () {int N, RN, LN, T = 0, flat [105] [105], MPL [105] [105]; Cha R c; while (scanf ("% d", & N)> 0) {for (INT I = 1; I <= N; I ++) {getchar (); for (Int J = 1; j <= N; j ++) {MIP [I] [J] = MPL [I] [J] = 0; scanf ("% C", & C); If (C = 'X ') flat [I] [J] = MPL [I] [J] =-1 ;}}rn = 0; For (INT I = 1; I <= N; I ++) // a row with multiple rows for (Int J = 1; j <= N; j ++) {While (flat [I] [J] =-1 & J <= N) J ++; rn ++; while (flat [I] [J]! =-1 & J <= N) {MIP [I] [J] = rn; j ++ ;}} Ln = 0; For (Int J = 1; j <= N; j ++) // change one column to multiple columns for (INT I = 1; I <= N; I ++) {While (MPL [I] [J] =-1 & I <= N) I ++; Ln ++; while (MPL [I] [J]! =-1 & I <= N) {MPL [I] [J] = ln; I ++ ;}} for (INT I = 1; I <= rn; I ++) map [I]. clear (); For (INT I = 1; I <= N; I ++) // create a row and column graph for (Int J = 1; j <= N; j ++) if (MIP [I] [J]! =-1) map [MIP [I] [J]. push_back (MPL [I] [J]); memset (match, 0, sizeof (MATCH); int ans = 0; For (INT I = 1; I <= rn; I ++) {for (Int J = 0; j <= ln; j ++) vist [J] = 0; ans + = find (I );} printf ("% d \ n", ANS );}}

Hnu13028attacking rooks (two-point match, one row is changed to multiple rows, and one column is changed to multiple columns)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.