Question
#include<stdio.h>
int get_ways(int num_of_dice, int num_of_faces, int S)
{
int arr[num_of_dice + 1][S + 1];
int dice, face, sm;
for(dice = 0; dice <= num_of_dice; dice++)
for(sm = 0; sm <= S; sm++)
arr[dice][sm] = 0;
for(sm = 1; sm <= S; sm++)
arr[1][sm] = 1;
for(dice = 2; dice <= num_of_dice; dice++)
{
for(sm = 1; sm <= S; sm++)
{
for(face = 1; face <= num_of_faces && face < sm; face++)
arr[dice][sm] += arr[dice - 1][sm - face];
}
}
return arr[num_of_dice][S];
}
int main()
{
int num_of_dice = 4, num_of_faces = 6, sum = 3;
int ans = get_ways(num_of_dice, num_of_faces, sum);
printf("%d",ans);
return 0;
}
a.
0
b.
1
c.
2
d.
3
Posted under Data Structures and Algorithms
Engage with the Community - Add Your Comment
Confused About the Answer? Ask for Details Here.
Know the Explanation? Add it Here.
Q. What is the output of the following code?
Similar Questions
Discover Related MCQs
Q. You are given a boolean expression which consists of operators &, | and ∧ (AND, OR and XOR) and symbols T or F (true or false). You have to find the number of ways in which the symbols can be parenthesized so that the expression evaluates to true. This is the boolean parenthesization problem. Which of the following methods can be used to solve the problem?
View solution
Q. Consider the expression T & F | T. What is the number of ways in which the expression can be parenthesized so that the output is T (true)?
View solution
Q. Consider the expression T & F ∧ T. What is the number of ways in which the expression can be parenthesized so that the output is T (true)?
View solution
Q. Consider the expression T | F ∧ T. In how many ways can the expression be parenthesized so that the output is F (false)?
View solution
Q. Which of the following gives the total number of ways of parenthesizing an expression with n + 1 terms?
View solution
Q. What is the maximum number of ways in which a boolean expression with n + 1 terms can be parenthesized, such that the output is true?
View solution
Q. How many different insertion sequences of the key values using the same hash function and linear probing will result in the hash table shown above?
View solution
Q. If ' h ' is a hashing function and it is used to hash ' n ' keys into a table of size ' m ' where n <= m . What is the expected number of collisions involving a particular key ' x ' ?
View solution
Q. Hashing technique which allocates fixed number of buckets is classified as
View solution
Q. Consider a hash table of size seven, with starting index zero, and a hash function (3x + 4)mod7. Assuming the hash table is initially empty, which of the following is the contents of the table when the sequence 1, 3, 8, 10 is inserted into the table using closed hashing? Note that _ denotes an empty location in the table.
View solution
Q. In linear hashing, formula used to calculate number of records if blocking factor, loading factor and file buckets are known is as
View solution
Q. Given a hash table T with 25 slots that stores 2000 elements, the load factor α for T is __________
View solution
Q. Which of these are core interfaces in the collection framework. Select the one correct answer.
View solution
Suggested Topics
Are you eager to expand your knowledge beyond Data Structures and Algorithms? We've curated a selection of related categories that you might find intriguing.
Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!