Data Structures & AlgorithmsHardCodeforces Div2 C · combinatorics
Problem: What is C(20, 10) mod 1000? Compute it with Pascal's triangle reduced mod 1000. Run the code.
Problem: What is C(20, 10) mod 1000? Compute it with Pascal's triangle reduced mod 1000. Run the code.
n, k = 20, 10
C = [[0] * (k + 1) for _ in range(n + 1)]
for i in range(n + 1):
C[i][0] = 1
for j in range(1, min(i, k) + 1):
C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % 1000
print(C[n][k])What is printed?- A. 756
- B. 184
- C. 856
- D. 656
Correct answer: A. 756
C(20, 10) = 184756, and 184756 mod 1000 = 756. Reducing modulo 1000 at each Pascal step keeps numbers small without changing the answer.
More Coding Interview Problems questions
- Problem: How many distinct palindromes can be formed by rearranging the letters of 'aabb' (distinct strings, all letters used)? Run the…
- Problem: What is the minimum number of deletions to make the string 'abcca' a palindrome? Use the palindromic-subsequence DP and print…
- Problem: Find the next lexicographic permutation of the digits '1243' (the smallest permutation strictly greater than it). Run the code…
- Problem: Find the length of the longest substring of 'AABABBA' that can be made all one letter after at most k = 1 replacement. Run the…
- Problem: How many bits must be flipped to convert A = 29 into B = 15? Run the code. python A, B = 29, 15 print(bin(A ^ B).count('1')) What…
- Problem: What is printed by the stack-based decoder for '3[a2[c]]'? It expands k[s] to s repeated k times. python def decode(s): stack =…