forked from Mohammed-Shoaib/Coding-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathE0076.cpp
More file actions
36 lines (29 loc) · 665 Bytes
/
E0076.cpp
File metadata and controls
36 lines (29 loc) · 665 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Problem Code: A1
#include <iostream>
#include <vector>
using namespace std;
string subsetSum(vector<int> coins, int n, int m) {
vector< vector<bool> > dp(n + 1, vector<bool>(m + 1));
for (int i=0 ; i <= n ; i++)
dp[i][0] = true;
for (int i=1 ; i <= n ; i++)
for (int j=1 ; j <= m ; j++) {
dp[i][j] = dp[i - 1][j];
if (j >= coins[i - 1])
dp[i][j] = dp[i][j] || dp[i - 1][j - coins[i - 1]];
}
return (dp[n][m]) ? "Yes" : "No";
}
int main() {
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
vector<int> coins(n);
for (int i=0 ; i < n ; i++)
cin >> coins[i];
cout << subsetSum(coins, n, m) << endl;
}
return 0;
}