A. Ivan the Fool and the Probability Theory

https://codeforces.com/contest/1239/problem/A

discription

given a \(n*m\) field in which every grid can be painted black and white. count the number of different situation, where every grid has at most one adjacent grid that shares the same color.

breakthrough

no idea. hard limitation causes headache.

but it turns out that we should utilize the harsh contraint wisely.
classial and direct solutions are excluded due to scope of \(n,m\). and once you take up looking for a pattern you will succeed

then you will find that if you have controlled the first row you will have controlled the whole universe unless what you have in the first row is:

  • something like WBWBWBWBWBW... then the next row is either WBWBWBWBW...(totally similar) or BWBWBWBWB..(total opposite). the third row presents the same pattern but with some limitations on columns and so does the followings. so in this situations the number of ways of where the first row altermates depends on the number of ways of all situation of the first column

apart from that, the partial answer is the number of ways of all situation of the first row except the situation mentioned above.

add them up and you will get the answer

上一篇:centos7下安装postgresql13


下一篇:Java的第一遍学习笔记 枚举和注释