ProgrammingVery hardCompetitive coding (CP)
How many tilings does a 2 by 5 board have with 2 by 1 dominoes? Compute with this recursive program.
How many tilings does a 2 by 5 board have with 2 by 1 dominoes? Compute with this recursive program.
#include <stdio.h>
int f(int n) {
if (n <= 1) return 1;
return f(n - 1) + f(n - 2);
}
int main(void) {
printf("%d", f(5));
}- A. 8
- B. 5
- C. 13
- D. 7
Correct answer: A. 8
A 2 by n board has F(n+1) domino tilings, and the recursion gives f(5) = 8.
More C Programming questions
- What is printed? c #include <stdio.h> #include <stdlib.h> int v[] = {30, 10, 20}; int cmp(const void a, const void b) { int i = (const int…
- What is printed? c #include <stdio.h> #include <stdlib.h> int cmp(const void a, const void b) { unsigned x = (const unsigned )a, y =…
- How many numbers from 1 to 100 have bit 3 set (value 8)? Compute with this program. c #include <stdio.h> int main(void) { int c = 0; for…
- What is printed? Assume uint16t is 16 bits. c #include <stdint.h> #include <stdio.h> int main(void) { uint16t x = 60000; uint16t y = x 2…
- How many ways are there to make 10 from unlimited coins of value 2, 3 and 5? Compute with this program. c #include <stdio.h> int ways(int…
- What is the length of the longest common subsequence of ABCBDAB and BDCABA? The program computes it by plain recursion without a table…