ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1260. Nudnik Photographer

Explanation
Posted by naik 11 Oct 2014 23:40
This problem solved with the left edge.

We look for position of "2".

We have three cases:
1) 12***** - "2" in the second position
2) 1*2**** - "2" in the third position

    1**2*** - "2" in the fourth position is impossible
    1***2** - "2" in the fifth position is impossible

3) 1******2 - "2" in the last position is possible (the one special case).
For example: 1357642

For each case find sub-task:
1) a[i-1]
2) is NOT a[i-2]
For 1*2**** there can only be one 132****, more accurate 1324***.
Therefore is a[i-3].
3) is 1

Recurrent expression: a[i] = a[i-1] + a[i-3] + 1.
And a precalculation:
a[1] = 1
a[2] = 1
a[3] = 2

A some answers to compare:
a[4] = 4
a[5] = 6
a[6] = 9
a[7] = 14