Given a set of non-negative integers, and a value sum, determine if there is a subset of the given set with sum equal to given sum.
Subset Sum Problem | DP-25 Given a set of non-negative integers, and a value sum, determine if there is a subset of the given set with sum equal to given sum. Example: Input: set[] = {3, 34, 4, 12, 5, 2}, sum = 9 Output: True //There is a subset (4, 5) with sum 9. // A recursive solution for subset sum problem #include <stdio.h> // Returns true if there is a subset of set[] with sun equal to given sum bool isSubsetSum( int set[], int n, int sum) { // Base Cases if (sum == 0) return true ; if (n == 0 && sum != 0) return false ; // If last element is greater than sum, then ignore it if (set[n-1] > sum) return isSubsetSum(set, n-1, sum); /* else, check if sum...
https://www.geeksforgeeks.org/zigzag-or-diagonal-traversal-of-matrix/
ReplyDelete