Need Help in understanding the solution to ADASEA (SPOJ)

Revision en1, by fan_balae, 2020-08-18 15:56:39

Problem link: https://www.spoj.com/problems/ADASEA/ 1

The implementation was pretty straightforward but I couldn’t understand how the expected value would work in this case.

I found a solution here: https://github.com/tr0j4n034/SPOJ/blob/master/ADASEA.cpp

The idea was to find all separate longest paths containing ‘#’ in them and just squaring them and adding it to the answer and finally dividing it by all the cells. Can someone tell me how does this work? Why does squaring all the paths work in this case?

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English fan_balae 2020-08-18 15:56:39 576 Initial revision (published)