ProgrammingVery hardCodeforces-style · placement coding round
What is printed?
What is printed?
def cnt_inc(a, k):
dp = [[0] * (k + 1) for _ in range(len(a))]
for i in range(len(a)):
dp[i][1] = 1
for j in range(i):
if a[j] < a[i]:
for L in range(2, k + 1):
dp[i][L] += dp[j][L - 1]
return sum(dp[i][k] for i in range(len(a)))
print(cnt_inc([1, 3, 2, 4], 2), cnt_inc([1, 3, 2, 4], 3))- A. 5 2
- B. 6 2
- C. 5 3
- D. 4 2
Correct answer: A. 5 2
The increasing pairs of [1, 3, 2, 4] number 5, and the increasing triples are 1-3-4 and 1-2-4.
More Python Programming questions
- What is printed? python from itertools import count, islice print(list(zip('abc', count(10, 5))), list(islice(count(1, 2), 3)))
- What is printed? python d = {k: v for k, v in [('a', 1), ('b', 2), ('a', 3)] if v > 1} print(d, {v: k for k, v in d.items()})
- What is printed? python first, mid, last = [1, 2, 3, 4, 5] a, (b, c) = 1, (2, 3, 4) print(mid, last, b, c)
- What is printed? python def ack(m, n): if m == 0: return n + 1 if n == 0: return ack(m - 1, 1) return ack(m - 1, ack(m, n - 1))…
- What is printed? python d = {'b': 2, 'a': 2, 'c': 1} print(sorted(d.items(), key=lambda kv: (-kv[1], kv[0])), sorted(d, key=d.get))
- Which statement about itertools.groupby is correct?