GATE CSE
First time here? Checkout the FAQ!
x
+1 vote
129 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 (50.5k points)  
retagged by | 129 views

1 Answer

+3 votes
Best answer

It is (N+1)th fibonacci number.

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

answered by Loyal (3.1k 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 Jul 2017
  1. Bikram

    3782 Points

  2. manu00x

    2464 Points

  3. Debashish Deka

    1832 Points

  4. joshi_nitish

    1494 Points

  5. Arnab Bhadra

    1096 Points

  6. Arjun

    1054 Points

  7. Hemant Parihar

    1050 Points

  8. Shubhanshu

    972 Points

  9. Ahwan

    876 Points

  10. akash.dinkar12

    642 Points


23,953 questions
30,895 answers
70,108 comments
29,273 users