Created
February 2, 2021 09:34
-
-
Save NDiiong/1304b7430ea116b785ed8a149e014b19 to your computer and use it in GitHub Desktop.
Subset Algorithm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
combine(new int[] { 1, 2, 3, 4, 5, 6 }, new List<int>(), 0); | |
static void combine(int[] a, List<int> outstr, int index) | |
{ | |
for (int i = index; i < a.Length; i++) | |
{ | |
int count = 0; | |
foreach (var item in outstr) | |
count += item; | |
if ((a[i] + count) == 10) | |
{ | |
foreach (var item in outstr) | |
Console.Write("{0}", item); | |
Console.Write("{0}", a[i]); | |
Console.WriteLine(); | |
} | |
outstr.Add(a[i]); | |
combine(a, outstr, i + 1); | |
outstr.Remove(a[i]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment