App 2.0开发模式的行业看法
676
2022-08-26
POJ 1681 Painter's Problem (高斯消元)
Description
Input
The first line contains a single integer t (1 <= t <= 20) that indicates the number of test cases. Then follow the t cases. Each test case begins with a line contains an integer n (1 <= n <= 15), representing the size of wall. The next n lines represent the original wall. Each line contains n characters. The j-th character of the i-th line figures out the color of brick at position (i, j). We use a ‘w’ to express a white brick while a ‘y’ to express a yellow brick.
Output
For each case, output a line contains the minimum number of bricks Bob should paint. If Bob can’t paint all the bricks yellow, print ‘inf’.
Sample Input
23yyyyyyyyy5Output
015
题意
给出一个 n×n
思路
考虑有 n×n 个多项式,每一个多项式涉及到上下左右以及自身的五个变量,其结果为 1 。
然后代入高斯消元求出方程组的解,若唯一解,统计 1 的个数;若有无穷多个解,枚举所有的自由变元找出最优解;若无解输出 inf 。
AC 代码
#include