Coodechef Paying up Problem Code: MARCHA1 Solution
Solution in C++:
///**********ALLAH IS ALMIGHTY************///
///AH Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
///**********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