Stanley's button
This is the story of a man named Stanley.
Stanley worked for a company in a big building where he was Employee #427. Employee #427's job was simple: he sat at his desk in Room 427 and pushed buttons on a keyboard. Orders came to him through a monitor on his desk telling him what buttons to push, how long to push them, and in what order. This is what Employee #427 did every day of every month of every year, and although others may have considered it soul rending, Stanley relished every moment that the orders came in, as though he had been made exactly for this job.
And then one day, something very peculiar happened: He had been at his desk for nearly an hour when he had realized not one single order had arrived on the monitor for him to follow. No one had shown up to give him instructions, call a meeting, or even say 'Hi'. Never in all his years at the company had this happened, this complete isolation. Something was very clearly wrong.
Shocked, frozen solid, Stanley found himself unable to move for the longest time. But as he came to his wits and regained his senses, he got up from his desk and stepped out of his office. To Stanley's surprise, outside his office lay a spacious, white room with a table of \(h \times w\) buttons placed in straight \(h\) rows and \(w\) columns.
Employee #427 began to push those buttons reluctantly, hoping for some reactions. He pushed exactly \(k\) different buttons, each of them (except the first one) shared at least an edge with another button he had pressed before. Furthermore, Stanley tried to balance the color of the buttons as follows: let \(R, G, Y\) be the numbers of red, green, and yellow buttons pushed respectively, this inequality holds: \[|R - G| + |G - Y| + |Y - R| \le 3\]
Perhaps you could assist Stanley in determining the number of ways he can press his buttons? Two button-pressing ways are considered distinct if there is at least one button that differs between them, with no consideration given to the order they are pressed.
Input
The first line contains two integers \(h\) and \(w\) \((1 \le h, w \le 50)\), the size of the table.
The next line contain integer \(k\) \((2 \le k \le 8)\), number of buttons Stanley pushed.
Next \(h\) lines, each line contain \(w\) characters (either \(G, Y\) or \(R\)) indicates color of the button.
Output
A single integer.
Scoring
- \(k \le 3, 1 \le h, w \le 10 :\) \(30\%\) point.
- \(4 \le k \le 8, 1 \le h, w \le 10:\) \(30\%\) point.
Example
Input:
2 9
2
R R Y R R G R R R
R Y Y G G G G G Y
Output:
13
Comments
Lời thoại: The Stanley Parable.