GATE CSE
First time here? Checkout the FAQ!
x
+1 vote
120 views
Given a integer N greater than zero.

How many sequences of 1's and 2's are there such that sum of the numbers in the sequence = N ?

(not necessary that every sequence must contain both 1 and 2 )

example :

for N = 2 ; 11,2 => ans = 2 sequences of 1's and 2's

for N = 3 ; 11,12,21 => ans = 3 sequences of 1's and 2's
asked in Combinatory by Veteran (43.9k points)  
retagged by | 120 views

1 Answer

+3 votes
Best answer

It is (N+1)th fibonacci number.

Observe the pattern: http://ideone.com/QLb1CZ

answered by Loyal (2.9k points)  
selected by
thanks this can be solved by dynamic as well as generating function or matrix exponentiation. similar to domino tiling
Yes, the recurrence relation is $F(0) = 1$, $F(1) = 1$ and $F(n) = F(n-1) + F(n-2)$, $\forall$ $n$ $\geq$ $2$.
@Air1. Hats off bro for you thought about the recurrance :)
The chapter on generating function from concrete mathematics, well described for this kind of problem.


Top Users Mar 2017
  1. rude

    5128 Points

  2. sh!va

    3054 Points

  3. Rahul Jain25

    2920 Points

  4. Kapil

    2732 Points

  5. Debashish Deka

    2602 Points

  6. 2018

    1574 Points

  7. Vignesh Sekar

    1422 Points

  8. Akriti sood

    1386 Points

  9. Bikram

    1350 Points

  10. Sanjay Sharma

    1128 Points

Monthly Topper: Rs. 500 gift card

21,535 questions
26,867 answers
61,199 comments
23,218 users