Problem A. Binomial Coefficient
The tasks in this section contain test function calls. Please do not change this code; otherwise, the assignment may not be accepted.
In previous sections, we solved the problems that can be described as functions with 1 parameter (fib(n)
, rabbit(n)
). Sometimes, the function depends on 2 or more parameters, for example, this one.
Swipe to start coding
Create the program to calculate Binomial coefficient C(n, k)
using dynamic programming. Since the function contains two parameters, the problem requires a two-dimensional array dp[n+1][n+1]
to store the values.
- Define the base cases:
C(n,0) = C(n,n) = 1
- Use the rule:
C(n,k) = C(n-1,k-1) + C(n-1,k)
.
Use Optimal Substructure and Overlapping Subproblems principles. If you’re unsure about how to store sub-solutions, open Hint.
Example 1. n=3, k=2 -> res = 3
Example2. n=10, k=4 -> res = 210
Solution
Merci pour vos commentaires !
single
Demandez à l'IA
Demandez à l'IA
Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion
Résumer ce chapitre
Expliquer le code dans file
Expliquer pourquoi file ne résout pas la tâche
Awesome!
Completion rate improved to 8.33
Problem A. Binomial Coefficient
Glissez pour afficher le menu
The tasks in this section contain test function calls. Please do not change this code; otherwise, the assignment may not be accepted.
In previous sections, we solved the problems that can be described as functions with 1 parameter (fib(n)
, rabbit(n)
). Sometimes, the function depends on 2 or more parameters, for example, this one.
Swipe to start coding
Create the program to calculate Binomial coefficient C(n, k)
using dynamic programming. Since the function contains two parameters, the problem requires a two-dimensional array dp[n+1][n+1]
to store the values.
- Define the base cases:
C(n,0) = C(n,n) = 1
- Use the rule:
C(n,k) = C(n-1,k-1) + C(n-1,k)
.
Use Optimal Substructure and Overlapping Subproblems principles. If you’re unsure about how to store sub-solutions, open Hint.
Example 1. n=3, k=2 -> res = 3
Example2. n=10, k=4 -> res = 210
Solution
Merci pour vos commentaires !
Awesome!
Completion rate improved to 8.33single