?
/* THE PROGRAM IS MADE BY PYY */ /*----------------------------------------------------------------------------// Copyright (c) 2011 panyanyany All rights reserved. URL : http://acm.hdu.edu.cn/showproblem.php?pid=1281 Name : 1281 棋盘游戏 Date : Tuesday, November 8, 2011 Time Stage : an hour Result: 4930281 2011-11-08 20:57:47 Accepted 1281 31MS 248K 1675 B C++ pyy Test Data : Review : 一开始想不明白,怎么样才能求那些“重要点”,甚至还想到从反面下手,先求 “不重要点”。但还是不得其解,于是看了人家的解题报告,发现可以试着删除 某个点,如果删除后最大的“车”数量有所减少,则证明它是“重要点”。 //----------------------------------------------------------------------------*/ #include <stdio.h> #include <vector> using std::vector ; #define MAXSIZE 109 int n, m, k ; int link[MAXSIZE], cover[MAXSIZE] ; bool map[MAXSIZE][MAXSIZE] ; int find (int cur) { int i, j ; for (i = 1 ; i <= m ; ++i) { if (cover[i] == false && map[cur][i] == true) { cover[i] = true ; if (link[i] == 0 || find (link[i])) { link[i] = cur ; return 1 ; } } } return 0 ; } int getSum () { int i ; int sum ; sum = 0 ; memset (link, 0, sizeof (link)) ; for (i = 1 ; i <= n ; ++i) { memset (cover, 0, sizeof (cover)) ; sum += find (i) ; } return sum ; } int main () { int i, j ; int x, y ; int sum, tmpSum, important, tcase ; tcase = 0 ; while (~scanf ("%d%d%d", &n, &m, &k)) { memset (map, false, sizeof (map)) ; for (i = 0 ; i < k ; ++i) { scanf ("%d%d", &x, &y) ; map[x][y] = true ; } sum = getSum () ; // 枚举所有可落“车”的点,分别删除,若车的最大数减少,则证明 // 该点为 “重要点” important = 0 ; for (i = 1 ; i <= n ; ++i) { for (j = 1 ; j <= m ; ++j) { if (map[i][j]) { map[i][j] = false ; tmpSum = getSum () ; map[i][j] = true ; if (tmpSum < sum) ++important ; } } } printf ("Board %d have %d important blanks for %d chessmen.\n", ++tcase, important, sum) ; } return 0 ; }?