Number of Ways to Earn Points

There is a test that has n types of questions. You are given an integer target and a 0-indexed 2D integer array types where types[i] = [counti, marksi] indicates that there are counti questions of the i^th type, and each one of them is worth marksi points.

Return the number of ways you can earn exactly target points in the exam. Since the answer may be too large, return it modulo 10^9 + 7.

Note that questions of the same type are indistinguishable.

  • For example, if there are 3 questions of the same type, then solving the 1^st and 2^nd questions is the same as solving the 1^st and 3^rd questions, or the 2^nd and 3^rd questions.
Example 1
Inputtarget = 6, types = [[6,1],[3,2],[2,3]]
Output7
There are seven indistinguishable combinations of question counts across the given types that sum to exactly 6 points.
Example 2
Inputtarget = 5, types = [[50,1],[50,2],[50,5]]
Output4
There are four ways to earn exactly 5 points: using five 1-point questions, three 1-point questions and one 2-point question, one 1-point question and two 2-point questions, or one 5-point question.

Constraints

  • 1 <= target <= 1000
  • n == types.length
  • 1 <= n <= 50
  • types[i].length == 2
  • 1 <= counti, marksi <= 50

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate