Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CAN SOMEONE GIVE AN IN-DEPTH EXPLANATION OF WHAT'S HAPPENING IN THIS CODE LINE BY LINE ? // CPP program to find if we can get

CAN SOMEONE GIVE AN IN-DEPTH EXPLANATION OF WHAT'S HAPPENING IN THIS CODE LINE BY LINE ? // CPP program to find if we can get given // sum using elements of given array. #include using namespace std; // maximum size of x const int MAX = 1000; // to check whether x is possible or not int ispossible[MAX];

void check(int arr[], int N) { ispossible[0] = 1; sort(arr, arr + N);

for (int i = 0; i < N; ++i) { int val = arr[i]; // if it is already possible if (ispossible[val]) continue; // make 1 to all it's next elements for (int j = 0; j + val < MAX; ++j) if (ispossible[j]) ispossible[j + val] = 1; } }

// Driver code int main() { int arr[] = { 4,2 }; int N = sizeof(arr) / sizeof(arr[0]); check(arr, N); int x = 100; if (ispossible[x]) cout << x << " is possible."; else cout << x << " is not possible."; return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

=+C&B (especially taxation) laws, regulations, and practices?

Answered: 1 week ago

Question

=+designing international assignment C&B packages.

Answered: 1 week ago