Problem Description
Loading...
Problem Analysis
A pattern-finding problem
First analyze the conditions for AC
- ZOJ can be AC; this is simple
- xzojx can be AC, that is, the count before z equals the count after j, with one between them
- If azbjc can be AC, then azbojac can also be AC
The third one has an “if”
That is, azbojac being AC has a precondition
That is, strings of this form can be derived step by step
Analyze the conditions
If condition 3 is satisfied, initially we must have a=c, b=1
Then each time we can derive recursively
the counts of the three o’s
a 2 a+c
a 3 2a+c
…
Because the precondition is a=c
Therefore
the three counts must satisfy
a b b*a
That is, the product of the count before Z and the count between Z and J must equal the count after J
So we can rule out other completely impossible cases
(no o between z and j; missing z or j)
Write the AC condition
cpp
| |
Problem link: HDU 3788 ZOJ Problem