adplus-dvertising
frame-decoration

Question

What is the output of the following code?
#include<stdio.h>
int get_min(int a, int b)
{
      if(a<b)
        return a;
      return b;
}
int minimum_time_required(int reach[][4],int spent[][5], int *entry, int *exit, int n)
{
      int t1[n], t2[n], i;
      t1[0] = entry[0] + spent[0][0];
      t2[0] = entry[1] + spent[1][0];
      for(i = 1; i < n; i++)
      {
          t1[i] = get_min(t1[i-1]+spent[0][i], t2[i-1]+reach[1][i-1]+spent[0][i]);
          t2[i] = get_min(t2[i-1]+spent[1][i], t1[i-1]+reach[0][i-1]+spent[1][i]);
      }
      return get_min(t1[n-1]+exit[0], t2[n-1]+exit[1]);
}
int main()
{
     int time_to_reach[][4] = {{16, 10, 5, 12},
                           {12, 4, 17, 8}};
     int time_spent[][5] = {{13, 5, 20, 19, 9},
                        {15, 10, 12, 16, 13}};
     int entry_time[2] = {12, 9};
     int exit_time[2] = {10, 13};
     int num_of_stations = 5;
     int ans = minimum_time_required(time_to_reach, time_spent, entry_time, exit_time, num_of_stations);
     printf("%d",ans);
     return 0;
}

a.

62

b.

69

c.

75

d.

88

Answer: (d).88

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. Given a string, you have to find the minimum number of characters to be inserted in the string so that the string becomes a palindrome. Which of the following methods can be used to solve the problem?

Q. In which of the following cases will the number of insertions to form a palindrome be minimum?

Q. In the worst case, the minimum number of insertions to be made to convert the string into a palindrome is equal to the length of the string.

Q. Consider the string “efge”. What is the minimum number of insertions required to make the string a palindrome?

Q. Consider the string “abbccbba”. What is the minimum number of insertions required to make the string a palindrome?

Q. Which of the following problems can be used to solve the minimum number of insertions to form a palindrome problem?

Q. Given a 2D matrix, find a submatrix that has the maximum sum. Which of the following methods can be used to solve this problem?

Q. In which of the following cases, the maximum sum rectangle is the 2D matrix itself?

Q. In which of the following cases, the maximum sum rectangle can be a 1 x 1 matrix containing the largest element?

Q. Consider a matrix in which all the elements are non-zero(at least one positive and at least one negative element). In this case, the sum of the elements of the maximum sum rectangle cannot be zero.

Q. Consider the 2×3 matrix {{1,2,3},{1,2,3}}. What is the sum of elements of the maximum sum rectangle?

Q. Consider the 2×2 matrix {{-1,-2},{-3,-4}}. What is the sum of elements of the maximum sum rectangle?

Q. Consider the 3×3 matrix {{2,1,-3},{6,3,4},{-2,3,0}}. What is the sum of the elements of the maximum sum rectangle?

Q. What is the time complexity of the brute force implementation of the maximum sum rectangle problem?

Q. The dynamic programming implementation of the maximum sum rectangle problem uses which of the following algorithm?

Q. Given an array, check if the array can be divided into two subsets such that the sum of elements of the two subsets is equal. This is the balanced partition problem. Which of the following methods can be used to solve the balanced partition problem?

Q. In which of the following cases, it is not possible to have two subsets with equal sum?

Q. What is the time complexity of the brute force algorithm used to solve the balanced partition problem?

Q. Consider a variation of the balanced partition problem in which we find two subsets such that |S1 – S2| is minimum. Consider the array {1, 2, 3, 4, 5}. Which of the following pairs of subsets is an optimal solution for the above problem?

Q. What is the sum of each of the balanced partitions for the array {5, 6, 7, 10, 3, 1}?