当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

2870:Light Up

题目描述
Light Up is a puzzle set in a rectangular board divided in smaller squares. Some squares in the board are ``empty'' (white squares the figure below), some squares are ``barriers'' (dark squares in the figure below). A barrier square may have an integer number i associated to it (0 <= i <= 4).


Figure 2: (a) Puzzle with 6 rows, 7 columns and 7 barriers; (b) a solution to the puzzle.


In this puzzle the goal is to ``light up'' all the empty squares by placing lamps in some of them (lamps are depicted as circles in the figure). Each lamp illuminates the square it is on, plus all squares in line with it, horizontally or vertically, up to a barrier square or the board end.

A winning configuration satisfies the following conditions:
  • all empty squares must be lit;
  • no lamp may be lit by another lamp;
  • all numbered barrier squares must have exactly that number of lamps adjacent to them (in the four squares above, below, and to the side);
  • non-numbered barrier squares may have any number of lamps adjacent to them.


You must write a program to determine the smallest number of lamps that are needed to reach a winning configuration.
输入解释
The input contains several test cases. The first line of a test case contains two integers N, M indicating respectively the number of rows and the number of columns of the board (1 <= N <= 7, 1 <= M <= 7). The second line contains one integer B indicating the number of barrier squares (0 <= B <= N × M). Each of the next B lines describe a barrier, containing three integers R, C and K, representing respectively the row number (1 <= R <= N), the column number (1 <= C <= M) and the barrier number (-1 <= K <= 4); K = -1 means the barrier is unnumbered. The end of input is indicated by N = M = 0.
输出解释
For each test case in the input your program must produce one line of output, containing either an integer indicating the smallest number of lamps needed to reach a winning configuration, in case such a configuration exists, or the words `No solution'.
输入样例
2 2
0
2 2
1
2 2 1
6 7
7
2 3 -1
3 3 0
4 2 1
5 4 3
5 6 2
1 7 -1
6 5 -1
0 0
输出样例
2
No solution
8

该题目是Virtual Judge题目,来自 北京大学POJ

题目来源 South America 2005

源链接: POJ-2870

最后修改于 2020-10-29T06:46:20+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 65536