1def SubsetSum(set, n, sum) :
2 # Base Cases
3 if (sum == 0) :
4 return True
5 if (n == 0 and sum != 0) :
6 return False
7 # ignore if last element is > sum
8 if (set[n - 1] > sum) :
9 return SubsetSum(set, n - 1, sum);
10 # else,we check the sum
11 # (1) including the last element
12 # (2) excluding the last element
13 return SubsetSum(set, n-1, sum) or SubsetSum(set, n-1, sumset[n-1])
14# main
15set = [2, 14, 6, 22, 4, 8]
16sum = 10
17n = len(set)
18if (SubsetSum(set, n, sum) == True) :
19 print("Found a subset with given sum")
20else :
21 print("No subset with given sum")