ProgrammingHardGATE CS · Campus placements
How many ways are there to write 5 as an unordered sum of 1s and 2s?
- A. 2
- B. 3
- C. 4
- D. 5
Correct answer: B. 3
The partitions are 1+1+1+1+1, 1+1+1+2 and 1+2+2, so there are 3. A DP over sums gives the same count.
More C Programming questions
- void rev(char s) { char e = s + strlen(s) - 1; while (s < e) { char t = s; s++ = e; e-- = t; } } After rev("abcde") runs on a writable…
- Which algorithm finds the maximum subarray sum of an array of n = 10^6 ints in time within a typical 1 second contest limit?
- char s = "hello"; What is strlen(s + 2)?
- int x = 1, y = 2, z = 3; int ptrs[3] = {&x, &y, &z}; What is ptrs[1] + ptrs[2]?
- printf("%d", 0x7FFFFFFF == 2147483647); What is printed?
- unsigned char c = 0xFF; unsigned int u = c << 8 | c; printf("%X", u); What is printed?