Dice Throw Problem Statement

You are provided with D dice, each having F faces numbered 1 to F, inclusive. Your task is to determine the number of possible ways to roll the dice such that the sum of the face-up numbers equals the target sum S.

The result should be returned modulo 109 + 7, as the answer can be large.

Input:

The first line contains an integer T which represents the number of test cases. The following line of each test case consists of three integers D, F, and S which correspond to the number of dice, the number of faces on each die, and the target sum respectively.

Output:

For each test case, output the number of ways to achieve the sum S on a separate line.

Example:

Input:
2
2 6 7
3 6 8
Output:
6
21

Constraints:

  • 1 <= T <= 5
  • 1 <= D, F <= 50
  • 1 <= S <= 10^3
  • Time limit: 1 sec

Note:

You are not required to print anything, as it is already handled. You only need to implement the function to return the result.

Follow Up:

Can you solve this using no more than O(S) additional space?

AnswerBot
4mo

The problem involves finding the number of ways to achieve a target sum by rolling a given number of dice with a certain number of faces.

  • Use dynamic programming to keep track of the number of ways to ...read more

Help your peers!
Select
Add answer anonymously...

Top Software Developer Intern Interview Questions Asked at Microsoft Corporation

Q. What were your responsibilities during your internship?
Q. What is the difference between polymorphism and inheritance?
Q. Given a string, reverse the order of characters using standard data structures a...read more
Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits