ProgrammingVery hardGATE CS · Campus placements
How many binary strings of length 5 contain no two adjacent 1s?
- A. 8
- B. 11
- C. 13
- D. 21
Correct answer: C. 13
Let f(n) count valid strings of length n, with f(1) = 2 and f(2) = 3, then f(n) = f(n-1) + f(n-2). This gives 2, 3, 5, 8, 13 for n = 1 to 5, so f(5) = 13.
More C Programming questions
- char s[] = "abc"; s[0] = 'x'; printf("%s", s); prints what?
- unsigned int n = 1u; unsigned int r = n << 31; What is r?
- int a = -7, b = 2; What is a / b b + a % b?
- int m[2][2] = {{1, 2}, {3, 4}}; int (r)[2] = m; What is r[1][0] + (r[0] + 1)?
- uint32t n = 100000u; uint32t t = n (n + 1) / 2; What is t?
- int x = 0; for (int i = 0; i < 5; i++) x = x ^ i << 1; What is x at the end?