Home / MCQ Bank / Computer
Computer Dynamic Programming In Data Structures Difficulty: Medium

What is space complexity of the following dynamic programming implementation of the dice throw problem where f is the number of faces, n is the number of dice and s is the sum to be found? #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 = 3, num_of_faces = 4, sum = 6; int ans = get_ways(num_of_dice, num_of_faces, sum); printf("%d",ans); return 0; }

Select the correct option to test your answer:

More Computer Questions

DCL provides commands to perform actions like The first electronic computer was developed by____________? A computer on the Internet is identified by: Which is the header that should be included first? What is the time complexity for inserting a new item in a ternary heap of n elements?