On 10/1/2018 at 12:51 PM, gamelearner said:
Hi,
I'm trying to understand the given below programming problem
https://codeforces.com/problemset/problem/1051/D
Doubt:
1) What is component here ? Is it something in grid or something else ?
Can anyone help me to understand this problem please ?
Thanks
Components have a good inductive definition:
Quote
Two cells A and B belong to the same component
- if they are neighbours,
- or if there is a neighbour of A that belongs to the same component with B.
While not what is usually meant with the word, neighbours are also defined satisfactorily:
Quote
Two cells are considered neighbours if they have a common border and share the same color.
In other words, the "components" are the connected components of the undirected graph that has the grid cells as nodes and edges between "neighbours". Are you familiar with graphs?
The example figure has 4 components, two white and two grey.
If you understand the examples (take your time to work them out on paper, the more complex first one with its 12 solutions in particular), it's only a matter of counting the colourings efficiently. Since it's homework, no hints about algorithms except that it's an easy and fun problem.