#P5457. [THUPC 2018] 生生不息
[THUPC 2018] 生生不息
Description
The Game of Life is a classic zero-player game.
The game is played on an grid board. Initially, some cells contain life, and the others do not.
When a new day begins, if among the 8 neighboring cells around a cell (cells on the boundary may have fewer than 8 neighbors), there were exactly or living cells on the previous day, then the life in this cell can continue to survive. If among the neighboring cells there were exactly living cells on the previous day and this cell was not alive on the previous day, then new life is born in this cell. In all other cases, any existing life in this cell dies, and no new life is created.
If on some day, there is no life in any cell on the board, then obviously in the following days there will never be life in any cell again. We say that life has gone extinct.
Now, Niuniu wants Feifei to decide whether each cell on the board is alive at the start of the game.
He wants to know how many different initial configurations Feifei can choose so that life on the board will never go extinct.
Input Format
The input contains multiple test cases. The first line contains an integer indicating the number of test cases. ()
Then each test case is described as follows:
- One line with positive integers and . ()
Output Format
For each test case, output line:
- Output one integer, representing the answer.
2
2 2
3 3
5
150
Hint
From the 2018 Tsinghua University Programming Contest and College Invitational Contest (THUPC 2018). Thanks to Pony.ai for supporting this contest.
Resources such as editorials can be found at https://github.com/wangyurzee7/THUPC2018.
Translated by ChatGPT 5
京公网安备 11011102002149号