subsetsum - / / / / / / Arup Guha 9/18/03 Example of...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
// Arup Guha // 9/18/03 // Example of many-to-one reductions from subset sum to partition and // from partition to subset sum. // Note: We assume that the input set to both problems only has positive // integers. #include <iostream.h> bool subsetSum(int values[], int size, int target); bool subsetSumHelp(int values[], int target, int size, int startindex); int PartToSum(int values[], int size); bool Partition(int values[], int size); bool alternateSS(int values[], int target, int size); void main() { int vals[10]; vals[0] = 1; vals[1] = 3; vals[2] = 5; vals[3] = 10; vals[4] = 20; vals[5] = 40; vals[6] = 80; vals[7] = 160; vals[8] = 319; vals[9] = 640; if (Partition(vals, 10)) cout << "Partition is successful.\n"; else cout << "Partition can't be done.\n"; if (alternateSS(vals, 177, 10)) cout << "Subset summing to 17 is found.\n"; else cout << "Subset summing to 17 is NOT found.\n"; } // Makes the initial call to the recursive method, indicating to // look for the subset in the entire array. bool subsetSum(int values[], int target, int size) {
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 2

subsetsum - / / / / / / Arup Guha 9/18/03 Example of...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online