Olympiad Problem

I think I failed this one.

--- The olympiad took place a few hours ago. ---

Colours

Miruna loves painting. In the last vacantion she went to her grandmother, and as she was bored, she started to paint her grandmother's house fence.
The fence is made of N boards one near the others. Miruna found in her grandmother's garage 5 boxes with colours. The colours are: While, Blue, Red, Green, Yellow. When she painted the fence, Miruna followed these rules:
- If a board is White, the next board is Blue;
- If a board is Blue, the next one is either White, or Red;
- If a board is Red, the next one is either Blue, or Green;
- If a board is Green, the next one is either Red, or Yellow;
- If a board is Yellow, then the next one is Green.
After she finished her "art", she asked herself in how many DIFFERENT ways she could paint the fence. Answer her question.

RESTRICTIONS
For 25% of tests 1 <= N <= 45
For the others N <= 5000

Example:

1
2
colours.in  colours.out
4           24 



----------
I could find that
1
2
3
4
5
6
7
8
9
10
Number of solutions for WHITE = No. solutions for Yellow; No. solutions for Red = Blue = Green. So Number of TOTAL solutions = 2x White + 3x Red.
Also, I calculated manually the solutions for  1<= N <=7

N=1 => 1
N=2 => 8
N=3 => 12
N=4 => 24
N=5 => 30
N=6 => 44
N=7 => 128


Please help me. I have to say that I'm in the 10th grade, so I do not know any GRAPH THEORY (...) (I figured it out that it can be solved with the Graph Theory, but I have no Calculus knowladge ... )
Don't multi-post.
http://www.cplusplus.com/forum/lounge/63538/
http://www.cplusplus.com/forum/general/63535/

EDIT:
I figured out the way.

The formula for all combinations is (indexed with n) is:
Cn = 2*Wn + 2*Bn + Rn

In which Wn, Bn and Rn respectively indicate the amount of combinations possible starting with just White, just Blue or just Red (times two since White acts the same as Yellow but mirrored and Blue acts the same as Green mirrored).

After looking at the results, you'll find that Bn = Wn+1 and that Rn=(Wn+Wn+2)/2.

Cn = 2*(Wn + Wn+1) + (Wn + Wn+2)/2

And Wn is given in a recursive way where Wn=Wn-1+Wn-2 when n is even and Wn=2*Wn-1 when n is odd.

My task is done here.

EDIT:
Some logic flaws fixed and put together in a single document:
http://depositfiles.com/files/85sjy53qe
Last edited on
Topic archived. No new replies allowed.