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

Complete the following dynamic programming implementation of the longest increasing subsequence problem: #include<stdio.h> int longest_inc_sub(int *arr, int len) { int i, j, tmp_max; int LIS[len]; // array to store the lengths of the longest increasing subsequence LIS[0]=1; for(i = 1; i < len; i++) { tmp_max = 0; for(j = 0; j < i; j++) { if(arr[j] < arr[i]) { if(LIS[j] > tmp_max) ___________; } } LIS[i] = tmp_max + 1; } int max = LIS[0]; for(i = 0; i < len; i++) if(LIS[i] > max) max = LIS[i]; return max; } int main() { int arr[] = {10,22,9,33,21,50,41,60,80}, len = 9; int ans = longest_inc_sub(arr, len); printf("%d",ans); return 0; }

Select the correct option to test your answer:

More Computer Questions

What will be the output of the following Java code? class box { int width; int height; int length; int volume; box() { width = 5; height = 5; length = 6; } void volume() { volume = width*height*length; } } class constructor_output { public static void main(String args[]) { box obj = new box(); obj.volume(); System.out.println(obj.volume); } } What is the purpose of using default arguments in C++ constructors? What does the term "Load Balancer" mean in the context of NiFi clusters? To set an exception to an AutoCorrect rule, click _______ on the menu bar and then click AutoCorrect Options to display the AutoCorrect dialog box. The problem of placing n queens in a chessboard such that no two queens attack each other is called as?