Coodechef Paying up Problem Code: MARCHA1 Solution


Solution in C++:
///**********ALLAH IS ALMIGHTY************///
///AH Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh

#include<bits/stdc++.h>
using namespace std;
bool subset(int a[], int n, int sum)
{
    if (sum == 0)
        return true;
    if (n == 0 && sum != 0)
        return false;
    if (a[n-1] > sum)
        return subset(a, n-1, sum);
    return subset(a, n-1, sum) ||subset(a, n-1, sum-a[n-1]);
}
int main()
{
    int t,n,m,i,sum;
    cin>>t;
    while(t--)
    {
        cin>>n>>m;
        int a[n];
        for(i=0; i<n; i++)
        {
            cin>>a[i];
        }
        if (subset(a,n,m) == true)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
}

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h ...

Powered by Blogger.