codingprolab@gmail.com

$50.00

Order Now
Category: CSCI 340

Description

5/5 - (7 votes)

You are given a 1-dimensional array of values a[]. You must try to select M distinct elements from a[] (i.e.,

without re-using any element, meaning, each element may be used at most once) to generate a specified sum N.

Can you generate a sum N using exactly M distinct elements from an array?

Write a function

int sumisn(int a[], int len, int m, int n)

where

a[] is a 1-dimensonal array of values

len is the number of elements in a[]

m is the number of elements from a[] that you must use to compute the sum

n is the sum you are trying to generate

and returns 1 if a[] has m distinct elements whose sum is n,

otherwise returns 0.

and returns the minimum number of tokens it takes to return change due c

or -1 if change is not possible or if len,c<1

File you must submit: soln_func.cc

Examples:

a[] = {1, 2, 3, 4} m=2 n=10

Returns: 0

Explanation: No sum of 2 distinct elements is 10.

a[] = {1, 2, 3, 4} m=4 n=10

Returns: 1

Explanation: 1 + 2 + 3 + 4=10

a[] = {1} m=1 n=1

Returns: 1

Explanation: 1

a[] = {1} m=4 n=1

Returns: 0

Explanation: a[] does not have 4 elements.

a[] = {-1, 0, -2, 5, 1, 6, 2} m=4 n=0

Returns: 1

Explanation: -1 + -2 + 1 + 2 = 0

a[] = {1, 2, 3, 4} m=2 n=8

Returns: 0

Explanation: No sum of 2 distinct elements is 8.

a[] = {1, 2, 3, 4} m=3 n=8

Returns: 1

Explanation: 1 + 3 + 4 = 8.

WhatsApp us