Function dpss::dp::sequence_matcher
source · [−]Expand description
Finds the integers from two vectors that sum to the same value.
This method assumes that the two vectors have One-to-Many relationships.
Each integer of the key vector corresponds to the multiple integers of the value vector.
Example
use subset_sum::dp::sequence_matcher;
let answer = sequence_matcher(&mut vec![3, 5, 7], &mut vec![1, 5, -3, 4, 5, 3]);
assert_eq!(answer, vec![
vec![
(vec![3], 3),
(vec![5], 5),
(vec![5, 4, -3, 1], 7),
],
vec![
(vec![3], 3),
(vec![4, 1], 5),
(vec![5, 5, -3], 7),
],
vec![
(vec![5, -3, 1], 3),
(vec![5], 5),
(vec![3, 4], 7),
],
]);
let answer_unchanged: Vec<Vec<(Vec<i32>, i32)>> = Vec::new();
let answer = sequence_matcher(&mut vec![10, 20], &mut vec![9, 21]);
assert_eq!(answer, answer_unchanged);