Bzoj 3175: [Tjoi2013] Attack device (Hungary)

Source: Internet
Author: User

Black and white dyed into a binary chart, and then can not be selected at the same time, the maximum number of matches m, T is the number can not be put, then the topic of the maximum point independent set of N*N-M-T

-------------------------------------------------------------------------

#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int MAXN = 209;const int Dir[8][2] = {{-1,-2}, {-2,-1}, {1,-2},{2,-1}, {-1, 2}, {-2, 1},{1, 2}, {2, 1}};struct Edge {int to;edge* Next;} E[MAXN * MAXN * 8], *pt = E, *HEAD[MAXN * MAXN];void Addedge (int u, int v) {pt->to = v; pt->next = head[u]; Head[u] = pt++;}Char STR[MAXN][MAXN];int N, VIS[MAXN * MAXN], C, MATCH[MAXN * MAXN], ans;int Id (int x, int y) {return x * N + y;}bool Dfs (int x) {For (edge* e = head[x]; e; e = e->next) if (vis[e->to]! = C) {vis[e->to] = C;if (!~match[e->to] | | DFS (MATCH[E->TO)) {match[e->to] = x;return true;}}return false;}bool Checky (int x, int y) {return (x + y) & 1;}void init () {scanf ("%d", &n);ans = n * n;for (int i = 0; i < N; i++) scanf ("%s", Str[i]);for (int i = 0; i < N; i++) {For (int j = 0; J < N; J + +) if (str[i][j] = = ' 0 ') {int id = ID (i, j);if (!checky (i, J)) {for (int k = 0; k < 8; k++) {int x = i + dir[k][0], y = j + dir[k][1];if (x >= 0 && x < N && y >= 0 && y < N && str[x][y] = = ' 0 ' && check Y (x, y))Addedge (ID, id (x, y));}}} elseans--;}}void Work () {memset (Match,-1, sizeof match);memset (Vis,-1, sizeof vis);int lim = n * N;For (C = 0; C < Lim; C + +) if (Dfs (C)) ans--;printf ("%d\n", ans);}int main () {init ();Work ();return 0;}

-------------------------------------------------------------------------

3175: [Tjoi2013] Attack device Time Limit:Ten Sec Memory Limit:MB
Submit:754 Solved:362
[Submit] [Status] [Discuss] Description

Given a 01 matrix, where you can place the attack device in 0 locations. Each attack device (x, y) can be attacked by the word "day" in 8 locations (x-1,y-2), (x-2,y-1), (x+1,y-2), (x+2,y-1), (x-1,y+2), (x-2,y+1), (x+1,y+2), (x+2,y+1)
The maximum number of devices that can be placed in the case of non-attack by the device.

Input The first line is an integer N, which indicates that the matrix size is n*n. Next n rows each row a length of N of 01 strings, representing the matrix. Output An integer that represents the maximum number of devices that can be placed if the device is not attacking. Sample Input 3
010
000
100
Sample Output 4HINT

100% Data n<=200

Source

Bzoj 3175: [Tjoi2013] Attack device (Hungary)

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.