Cho một tập hợp các số nguyên không âm và tổng giá trị, xác định xem có một tập hợp con của tập hợp đã cho với tổng bằng với tổng đã cho. & NBSP;
Example:
Input: set[] = {3, 34, 4, 12, 5, 2}, sum = 9 Output: True There is a subset [4, 5] with sum 9. Input: set[] = {3, 34, 4, 12, 5, 2}, sum = 30 Output: False There is no subset that add up to 30.
Phương pháp 1: đệ quy.Approach: Đối với phương pháp đệ quy, chúng tôi sẽ xem xét hai trường hợp. & Nbsp; Recursion.
Approach: For the recursive approach we will consider two cases.
- Hãy xem xét phần tử cuối cùng và bây giờ tổng số = tổng mục tiêu - giá trị của phần tử cuối cùng và số phần tử = tổng phần tử - 1required sum = target sum – value of ‘last’ element and number of elements = total elements – 1
- Rời khỏi phần tử ‘cuối cùng và bây giờ tổng yêu cầu = tổng mục tiêu và số lượng phần tử = tổng số phần tử - 1required sum = target sum and number of elements = total elements – 1
Sau đây là công thức đệ quy cho vấn đề ISSUBSETSUM []. & NBSP;
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0
Chúng ta hãy xem xét mô phỏng của cách tiếp cận ở trên-: & nbsp;
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}
C++
#include
using
namespace
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 00
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 01
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 02
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 04
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 06
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 08
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 09
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}2
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}5
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}6
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}9
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
Found a subset with given sum2
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}6
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
Found a subset with given sum6
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
Found a subset with given sum9
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]2
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]3
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]4
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]7
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 09
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T1
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T4
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T7
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T8
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T9
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T8
Found a subset with given sum1
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0____21
Found a subset with given sum4
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}5
Found a subset with given sum6
Found a subset with given sum7
Found a subset with given sum8
Found a subset with given sum9
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}6
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
#include
2set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
Found a subset with given sum8
#include
5set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}6
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
#include
9if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
C
using
1
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 01
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 02
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 04
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 06
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 08
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 09
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}2
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}5
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}6
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}9
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
Found a subset with given sum2
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}6
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
Found a subset with given sum6
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
Found a subset with given sum9
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]2
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]3
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]4
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]7
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 09
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T1
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T4
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T7
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T8
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T9
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T8
Found a subset with given sum1
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0____21
Found a subset with given sum4
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}5
Found a subset with given sum6
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 039
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
Found a subset with given sum9
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 042
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
#include
2set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 039
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
#include
5isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 042
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
#include
9if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
C
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]2
Java
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 054
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 055
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 09
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 057
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 058
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 02
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 061
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 062
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 06
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 08
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 071
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 072
Found a subset with given sum6
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}5
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}6
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 080
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 072
Found a subset with given sum6
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
Found a subset with given sum2
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}6
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 089
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 090
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 091
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}03
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 090
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}05
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 090
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}07
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 094
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 090
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 096
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 094
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 090
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}01
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 09
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}11
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 057
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}13
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}14
Các
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}34
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}35
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}6
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}46
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}47
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 062
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}49
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}50
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 042
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
#include
2isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}46
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}56
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 062
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}49
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}59
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 042
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 094
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 090
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 096
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
Python3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 094
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 090
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}01
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}11
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 057
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}13
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}14
Các
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}34
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}35
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}6
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}39
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
Found a subset with given sum4
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}5
Found a subset with given sum6
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}64
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 02
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}66
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}67
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}68
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}69
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}68
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}74
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}74
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}66
Found a subset with given sum16
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}96
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 090
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}21
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}68
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}96
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}66
Found a subset with given sum33
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}96
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 090
Found a subset with given sum36
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}80
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0____21
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}83
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}74
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}74
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 072
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}69
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}90
Các
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
Found a subset with given sum72
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
Found a subset with given sum9
Found a subset with given sum6
#include
2
Found a subset with given sum77
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
Found a subset with given sum72
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
#include
5Found a subset with given sum6
C#
using
Found a subset with given sum84
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 054
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 055
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 057
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 01
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 02
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
Found a subset with given sum92
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 09
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}2
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}5
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}6
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}9
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
Found a subset with given sum2
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}6
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}66
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]19
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 02
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}66
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]24
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 02
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}66
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]29
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]30
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]31
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}66
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]33
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}66
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]35
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0____211
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 057
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}13
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]42
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 09
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
Found a subset with given sum92 ____266
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]49
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T4
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T7
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}66
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]57
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
Found a subset with given sum62
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}66
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]62
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}5
Found a subset with given sum6
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]66
Found a subset with given sum9
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 042
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
#include
2isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]66
#include
5isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 042
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
PHP
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]78
Is
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 09
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0____21
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]85
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]92
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]95
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0____21
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]83
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]92
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T03
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]81
Found a subset with given sum39
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]83
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T10
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]85
Found a subset with given sum6
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 02
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]81
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}21
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]83
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T19
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]85__
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 02
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]81
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}21
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]83
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T19
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]85
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T30
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 02
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]81
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}21
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]83
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T36
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T37
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]85
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T39
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]81
Found a subset with given sum39
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]83
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T43
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]81
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T46
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T47
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T48
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]85
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T50
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]83
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T52
Is
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T62
Found a subset with given sum9
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}6
#include
2
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T62
#include
5set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}6
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T70
JavaScript
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T71
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]79
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T74
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 09
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}2
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}5
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}6
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}9
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
Found a subset with given sum2
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}6
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}66
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]19
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 02
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}66
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]24
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 02
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}66
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]29
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]30
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]4
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
Found a subset with given sum05
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
Found a subset with given sum07
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
Found a subset with given sum09
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0____211
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 057
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}13
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]42
Found a subset with given sum15
Found a subset with given sum16
Found a subset with given sum9
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 042
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
#include
2Found a subset with given sum15
Found a subset with given sum16
#include
5isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 042
Found a subset with given sum25
set[]={3, 4, 5, 2}
sum=9
[x, y]= 'x' is the left number of elements,
'y' is the required sum
[4, 9]
{True}
/ \
[3, 6] [3, 9]
/ \ / \
[2, 2] [2, 6] [2, 5] [2, 9]
{True}
/ \
[1, -3] [1, 2]
{False} {True}
/ \
[0, 0] [0, 2]
{True} {False}
3isSubsetSum[set, n, sum]
= isSubsetSum[set, n-1, sum] ||
isSubsetSum[set, n-1, sum-set[n-1]]
Base Cases:
isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0
isSubsetSum[set, n, sum] = true, if sum == 0
3Found a subset with given sum
92 ____266 if [A[i-1] > j]
DP[i][j] = DP[i-1][j]
else
DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]
49
Found a subset with given sum
set[]={3, 4, 5, 2}
sum=9
[x, y]= 'x' is the left number of elements,
'y' is the required sum
[4, 9]
{True}
/ \
[3, 6] [3, 9]
/ \ / \
[2, 2] [2, 6] [2, 5] [2, 9]
{True}
/ \
[1, -3] [1, 2]
{False} {True}
/ \
[0, 0] [0, 2]
{True} {False}
3isSubsetSum[set, n, sum]
= isSubsetSum[set, n-1, sum] ||
isSubsetSum[set, n-1, sum-set[n-1]]
Base Cases:
isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0
isSubsetSum[set, n, sum] = true, if sum == 0
3 set[]={3, 4, 5, 2}
target=6
0 1 2 3 4 5 6
0 T F F F F F F
3 T F F T F F F
4 T F F T T F F
5 T F F T T T F
2 T F T T T T T
4The above solution
may try all subsets of given set in worst case. Therefore time complexity of the above solution is exponential. The problem is in-fact NP-Complete [There is no known polynomial time solution for this problem].
set[]={3, 4, 5, 2}
sum=9
[x, y]= 'x' is the left number of elements,
'y' is the required sum
[4, 9]
{True}
/ \
[3, 6] [3, 9]
/ \ / \
[2, 2] [2, 6] [2, 5] [2, 9]
{True}
/ \
[1, -3] [1, 2]
{False} {True}
/ \
[0, 0] [0, 2]
{True} {False}
3isSubsetSum[set, n, sum]
= isSubsetSum[set, n-1, sum] ||
isSubsetSum[set, n-1, sum-set[n-1]]
Base Cases:
isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0
isSubsetSum[set, n, sum] = true, if sum == 0
3 set[]={3, 4, 5, 2}
target=6
0 1 2 3 4 5 6
0 T F F F F F F
3 T F F T F F F
4 T F F T T F F
5 T F F T T T F
2 T F T T T T T
7set[]={3, 4, 5, 2}
sum=9
[x, y]= 'x' is the left number of elements,
'y' is the required sum
[4, 9]
{True}
/ \
[3, 6] [3, 9]
/ \ / \
[2, 2] [2, 6] [2, 5] [2, 9]
{True}
/ \
[1, -3] [1, 2]
{False} {True}
/ \
[0, 0] [0, 2]
{True} {False}
66if [A[i-1] > j]
DP[i][j] = DP[i-1][j]
else
DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]
57 To solve the problem in
Pseudo-polynomial time use the Dynamic programming.
So we will create a 2D array of size [arr.size[] + 1] * [target + 1] of type boolean. The state DP[i][j] will be true if there exists a subset of elements from A[0….i] with sum value = ‘j’. The approach for the problem is:
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}
3set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}
1Found a subset with given sum
62set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}
66if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]
62set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}
5Found a subset with given sum
6- PHPsum=’j’ OR any previous states experienced a value ‘j – A[i]’ which will solve our purpose.
Is
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0____21
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]85
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]92
set[]={3, 4, 5, 2}
sum=9
[x, y]= 'x' is the left number of elements,
'y' is the required sum
[4, 9]
{True}
/ \
[3, 6] [3, 9]
/ \ / \
[2, 2] [2, 6] [2, 5] [2, 9]
{True}
/ \
[1, -3] [1, 2]
{False} {True}
/ \
[0, 0] [0, 2]
{True} {False}
3set[]={3, 4, 5, 2}
sum=9
[x, y]= 'x' is the left number of elements,
'y' is the required sum
[4, 9]
{True}
/ \
[3, 6] [3, 9]
/ \ / \
[2, 2] [2, 6] [2, 5] [2, 9]
{True}
/ \
[1, -3] [1, 2]
{False} {True}
/ \
[0, 0] [0, 2]
{True} {False}
4 if [A[i-1] > j]
DP[i][j] = DP[i-1][j]
else
DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]
95
using
1
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0____21
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]83
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]92
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 09
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T03
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]81
Found a subset with given sum39
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]83
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T10
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]85
Found a subset with given sum6
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
Found a subset with given sum45
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}5
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}6
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 02
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]81
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}21
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]83
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T19
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]85__
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
Found a subset with given sum54
Found a subset with given sum2
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}6
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 02
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]81
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}21
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]83
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T19
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]85
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T30
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 02
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]81
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}21
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]83
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T36
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T37
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]85
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T39
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]81
Found a subset with given sum39
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]83
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T43
Found a subset with given sum70
Found a subset with given sum71
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]81
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T46
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T47
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T48
Found a subset with given sum70
Found a subset with given sum76
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 062
Found a subset with given sum78
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]85
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T50
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]83
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T52
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 09
Is
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T4
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T7
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T8
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T9
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T8
Found a subset with given sum1
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0____21
Found a subset with given sum4
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}5
Found a subset with given sum6
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 039
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
Found a subset with given sum9
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 042
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
#include
2set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 039
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
#include
5isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 042
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
#include
9if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
C++
#include
using
namespace
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 00
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 01
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 02
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 04
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 06
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 08
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 09
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 01
Found a subset with given sum38
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
Found a subset with given sum40
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
Found a subset with given sum43
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
Found a subset with given sum45
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}5
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}6
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
Found a subset with given sum40
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
Found a subset with given sum52
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
Found a subset with given sum54
Found a subset with given sum2
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}6
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
Found a subset with given sum40
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
Found a subset with given sum61
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
Found a subset with given sum40
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
Found a subset with given sum66
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
Found a subset with given sum69
Found a subset with given sum70
Found a subset with given sum71
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
Found a subset with given sum74
Found a subset with given sum70
Found a subset with given sum76
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 062
Found a subset with given sum78
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
Found a subset with given sum85
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]7
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 09
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T1
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T4
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T7
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T8
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T9
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T8
Found a subset with given sum1
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0____21
Found a subset with given sum4
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}5
Found a subset with given sum6
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
#include
9set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
#include
2set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
Found a subset with given sum8
#include
5set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}6
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
#include
9if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
using
namespace
isSubsetSum[set, n, sum]
= isSubsetSum[set, n-1, sum] ||
isSubsetSum[set, n-1, sum-set[n-1]]
Base Cases:
isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0
isSubsetSum[set, n, sum] = true, if sum == 0
0
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 01
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 02
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 04
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 06
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 08
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 01
Found a subset with given sum38
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
Found a subset with given sum40
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
Found a subset with given sum43
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 09
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
Found a subset with given sum40
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
Found a subset with given sum52
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
Found a subset with given sum40
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
Found a subset with given sum61
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
Found a subset with given sum40
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
Found a subset with given sum66
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
Found a subset with given sum69
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
using
69isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 072
using
71Found a subset with given sum2
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}6
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
Found a subset with given sum74
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
Found a subset with given sum85
Found a subset with given sum70
using
89isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 090
using
47isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]7
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T37
using
98using
99namespace
00
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 090
namespace
02isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 090
using
47isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T1
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
Found a subset with given sum8
Found a subset with given sum9
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}6
Java
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 09
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 054
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 055
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 057
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 058
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 02
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 061
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 062
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 06
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 08
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 058
using
40using
41 isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 058__
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}46
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}47
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 062
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}49
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}50
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 042
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
#include
2isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}46
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}56
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 062
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}49
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}59
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 042
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
Found a subset with given sum8
Found a subset with given sum9
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}6
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
Python3
Java
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 054
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 055
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 057
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 058
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 02
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 061
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 062
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 06
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 08
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 058
using
40using
41 isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 058__
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
Found a subset with given sum40
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
using
52isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 072
using
54isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
using
56isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 072
using
58set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}5
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}6
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
Found a subset with given sum40
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
using
52isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 090
using
67set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
Found a subset with given sum40
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
using
52isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 090
using
80isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
Found a subset with given sum40
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
using
85isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 090
using
87Found a subset with given sum70
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
using
94isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 090
Found a subset with given sum36
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
namespace
11set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}11
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 057
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}13
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}14
Các
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}34
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}35
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}6
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}66
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}74
Found a subset with given sum39
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}20
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}21
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}2222221
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}24
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}21
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}26____221
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}28
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}21__
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}68
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}74
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}35
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
Found a subset with given sum55
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}74
Found a subset with given sum57
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}666____66
Is
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
Found a subset with given sum72
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
Found a subset with given sum9
Found a subset with given sum6
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
#include
2Found a subset with given sum77
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
Found a subset with given sum72
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
#include
5Found a subset with given sum6
C#
using
Found a subset with given sum84
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 054
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 055
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 057
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 01
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 02
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
Found a subset with given sum92
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 09
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 01____1178
using
41 isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 01
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0181
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
Found a subset with given sum40
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
Found a subset with given sum43
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0188
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}5
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}6
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
Found a subset with given sum40
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
Found a subset with given sum52
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0197
Found a subset with given sum2
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}6
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
Found a subset with given sum40
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0204
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
Found a subset with given sum40
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0209
Found a subset with given sum70
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0211
Found a subset with given sum70
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0214
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}66
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0216
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T37
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0218
using
99
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0220
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}66
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0222
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0229
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0____211
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 057
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}13
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]42
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 09
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
Found a subset with given sum92 ____266
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]49
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T4
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T7
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}66
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]57
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
Found a subset with given sum62
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}66
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]62
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}5
Found a subset with given sum6
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]66
Found a subset with given sum9
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 042
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
#include
2isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]66
#include
5isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 042
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
PHP
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]78
Is
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 09
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0283
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T46
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T47
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T47
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0288
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
Found a subset with given sum40
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0291
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0292
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0293
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0292
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0283
Found a subset with given sum39
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0292
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0304
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
Found a subset with given sum40
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0291
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0292
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0309
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0292
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0283
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0318
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 02929____1320
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
Found a subset with given sum40
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0292
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0309
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0292
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0295__
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 09
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
Found a subset with given sum40
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0337
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0309
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0337
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0295__
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 09
Các
Found a subset with given sum70
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0283
Found a subset with given sum39
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0292
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0360
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0337
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0362
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0363
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0283
Found a subset with given sum39
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0292
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0367
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0337
using
47isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0337
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0374
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]81
Found a subset with given sum39
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0292
Found a subset with given sum70
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0283
Found a subset with given sum39
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0292
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0360
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0337
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0362
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0386
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0283
Found a subset with given sum39
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0292
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0367
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0337
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0392
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0386
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0283
Found a subset with given sum39
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0292
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0397
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0337
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0399
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 062
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]81
Found a subset with given sum39
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0292
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0404
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0283
Found a subset with given sum39
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]83
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0360
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]85
using
47if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]81
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T46
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T47
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T48
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]85
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T50
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]83
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T46
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0426
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]81
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 042
Is
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T62
Found a subset with given sum9
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}6
#include
2
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T62
#include
5set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}6
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T70
JavaScript
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T71
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]79
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T74
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 09
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0455
using
41 isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0457
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
Found a subset with given sum40
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0460
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 09
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0464
using
41 isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0457
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
Found a subset with given sum40
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0469
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 09
Found a subset with given sum70
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0473
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
Found a subset with given sum40
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0480
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
Found a subset with given sum54
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}5
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}6
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
Found a subset with given sum40
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0487
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
Found a subset with given sum45
Found a subset with given sum2
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}6
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
Found a subset with given sum40
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0494
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
Found a subset with given sum40
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0497
Found a subset with given sum70
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0499
Found a subset with given sum70
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0502
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T37
using
98using
99
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0506
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
namespace
11set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
Found a subset with given sum05
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
Found a subset with given sum07
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
Found a subset with given sum09
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0____21
Found a subset with given sum4
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}5
Found a subset with given sum6
Found a subset with given sum15
Found a subset with given sum16
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}47
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}49
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}50
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 042
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
#include
2Found a subset with given sum15
Found a subset with given sum16
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}56
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}49
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}59
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 042
Found a subset with given sum25
Đầu ra
Found a subset with given sum
Phân tích độ phức tạp:
Độ phức tạp về thời gian: O [tổng*n], trong đó tổng là 'tổng mục tiêu' và 'n' là kích thước của không gian mảng . + O [n] cho không gian ngăn xếp đệ quy O[sum*n], where sum is the ‘target sum’ and ‘n’ is the size of
array.
Auxiliary Space: O[sum*n], as the size of 2-D array is sum*n. + O[n] for recursive stack space
Kỹ thuật ghi nhớ để tìm tập hợp con:
Method:
- Trong phương pháp này, chúng tôi cũng tuân theo cách tiếp cận đệ quy nhưng trong phương pháp này, chúng tôi sử dụng một ma trận 2 chiều khác trong & nbsp; trước tiên chúng tôi khởi tạo với -1 hoặc bất kỳ giá trị âm nào.
- Trong phương pháp này, chúng tôi tránh được một vài cuộc gọi đệ quy được lặp đi lặp lại rằng tại sao chúng tôi sử dụng ma trận 2 chiều. Trong ma trận này, chúng tôi lưu trữ giá trị của giá trị cuộc gọi trước đó.
Dưới đây là việc thực hiện phương pháp trên:
C++
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0542
using
namespace
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 00
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0547
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0549
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0551
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 06
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 09
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}2
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0562
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0____21
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0565
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
#include
9set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0____21
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0571
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0574
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0____21
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0577
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0580
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
#include
2set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 09
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0587
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0386
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0589
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]7
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 09
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0597
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0598
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T8
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0600
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0603
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0606
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0609
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0__21
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0612
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 09
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0616
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0617
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0618
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
#include
2set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0616
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0625
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0618
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
Java
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 054
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 055
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 057
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0549
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 09
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 06444
using
41 isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0647
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 090
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0649
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 090
using
47set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
Found a subset with given sum40
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
using
52isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 090
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0658
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
Found a subset with given sum40
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
using
85isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 090
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0665
Found a subset with given sum70
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0667
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 090
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}6
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 071
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 072
Found a subset with given sum6
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 090
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}6
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0685
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 072
Found a subset with given sum6
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 072
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}6
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0694
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 090
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0696
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 090
Found a subset with given sum6
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0701
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 090
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0703
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0706
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 090
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 091
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0701
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 090
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0713
Found a subset with given sum70
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0715
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 090
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 096
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
#include
2 isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 09
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0723
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 090
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0725
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 072
Found a subset with given sum70
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0728
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 090
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0730
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 090
Found a subset with given sum36
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0386
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0734
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 072
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0736
Found a subset with given sum70
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0701
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 090
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0741
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 090
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}6
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
#include
2Found a subset with given sum70
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0701
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 090
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0741
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 072
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}6
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0____211
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 057
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}13
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0763
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 09
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T7
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}28
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}6
Các
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}34
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}26
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}6
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0791
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 072
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0736
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}46
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0796
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 042
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
#include
2isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}46
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0804
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 042
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
Python3
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0809
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}74
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0811
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}96
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 090
Found a subset with given sum40
namespace
80__set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}64
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0829
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}68
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}69
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}68
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}74
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}74
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 090
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0__21
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0845
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}74
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 072
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}69
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 072
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0854
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}96
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 090__
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0866
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}96
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 090
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0360
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}68
Found a subset with given sum51
Is
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0866
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}96
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 090__
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0866
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}96
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 090
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0360
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}68
Found a subset with given sum51
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
#include
2Found a subset with given sum77
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0866
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}96
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 090__
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0866
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}96
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 090__
Found a subset with given sum55
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}74
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}28
Các
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}68
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}74
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}26
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0958
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}68
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0960
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
Found a subset with given sum72
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0617
Found a subset with given sum6
#include
2
Found a subset with given sum77
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
Found a subset with given sum72
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0625
Found a subset with given sum6
C#
using
Found a subset with given sum84
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 054
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0976
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 09
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 057
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0549
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0983__
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 09
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0992
using
41 isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0995
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
Found a subset with given sum40
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
Found a subset with given sum61
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
Found a subset with given sum40
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 040
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
Found a subset with given sum66
Found a subset with given sum70
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}007
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}2
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0562
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0565
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
#include
9set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}026
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}029
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0577
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}035
Found a subset with given sum70
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}037
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
#include
2 isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 09
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}043
Found a subset with given sum70
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}045
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0386
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}047
Found a subset with given sum70
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}050
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
#include
2Found a subset with given sum70
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}057
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}11
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 057
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}13
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}066
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 09
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0603
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}074
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0609
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}080
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}082
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0796
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 042
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
#include
2isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}082
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0804
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 042
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}0
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
JavaScript
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T71
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]79
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}099
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}2
Found a subset with given sum70
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0562
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0565
Found a subset with given sum70
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
#include
9isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0571
Found a subset with given sum70
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0574
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0577
Found a subset with given sum70
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0580
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
#include
2 isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 09
Found a subset with given sum70
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}4
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}129
set[]={3, 4, 5, 2} target=6 0 1 2 3 4 5 6 0 T F F F F F F 3 T F F T F F F 4 T F F T T F F 5 T F F T T T F 2 T F T T T T T37
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0589
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}137
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}139
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}141
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}143
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}146
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
Found a subset with given sum16
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0617
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}49
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}151
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 042
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
#include
2 isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 09
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 074
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}1
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}043
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
if [A[i-1] > j] DP[i][j] = DP[i-1][j] else DP[i][j] = DP[i-1][j] OR DP[i-1][j-A[i-1]]5
Found a subset with given sum25
Found a subset with given sum
70set[]={3, 4, 5, 2}
sum=9
[x, y]= 'x' is the left number of elements,
'y' is the required sum
[4, 9]
{True}
/ \
[3, 6] [3, 9]
/ \ / \
[2, 2] [2, 6] [2, 5] [2, 9]
{True}
/ \
[1, -3] [1, 2]
{False} {True}
/ \
[0, 0] [0, 2]
{True} {False}
4 set[]={3, 4, 5, 2}
sum=9
[x, y]= 'x' is the left number of elements,
'y' is the required sum
[4, 9]
{True}
/ \
[3, 6] [3, 9]
/ \ / \
[2, 2] [2, 6] [2, 5] [2, 9]
{True}
/ \
[1, -3] [1, 2]
{False} {True}
/ \
[0, 0] [0, 2]
{True} {False}
050
Found a subset with given sum
70set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}
4set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}
057 O[sum*n], where sum is the ‘target sum’ and ‘n’ is the size of array.set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}
0set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}
11isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0
57set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}
13set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}
066 O[sum*n] + O[n] -> O[sum*n] = the size of 2-D array is sum*n and O[n]=auxiliary stack space.
set[]={3, 4, 5, 2} sum=9 [x, y]= 'x' is the left number of elements, 'y' is the required sum [4, 9] {True} / \ [3, 6] [3, 9] / \ / \ [2, 2] [2, 6] [2, 5] [2, 9] {True} / \ [1, -3] [1, 2] {False} {True} / \ [0, 0] [0, 2] {True} {False}3
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 03
isSubsetSum[set, n, sum] = isSubsetSum[set, n-1, sum] || isSubsetSum[set, n-1, sum-set[n-1]] Base Cases: isSubsetSum[set, n, sum] = false, if sum > 0 and n == 0 isSubsetSum[set, n, sum] = true, if sum == 0603
Perfect Sum Problem [Print all subsets with given sum]
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.