forked from sameer2800/Lightoj-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path1235-Coin_Change_IV.cpp
76 lines (58 loc) · 1.24 KB
/
1235-Coin_Change_IV.cpp
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <bits/stdc++.h>
#define ll long long
#define MAX 100100
using namespace std;
ll arr1[10], arr2[20];
set <ll> set1;
ll n, k;
ll glob;
void recursive_generate(ll val, ll ind)
{
set1.insert(val);
if (ind == n / 2)
return;
recursive_generate(val + 0 , ind + 1);
recursive_generate(val + arr1[ind] , ind + 1);
recursive_generate(val + 2 * arr1[ind] , ind + 1);
}
ll flag = 0;
void find_and_recursive2(ll val, ll ind)
{
if (set1.find(k - val) != set1.end()) {
flag = 1;
return;
}
if (flag == 1)
return;
if (ind == n)
return;
find_and_recursive2(val, ind + 1);
find_and_recursive2(val + arr2[ind] , ind + 1);
find_and_recursive2(val + 2 * arr2[ind] , ind + 1);
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("/home/sameer/Documents/sameer/input.sam", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
ll i, j, m, t, cont, a, b;
cin >> t;
ll cases = t;
while (t--) {
set1.clear();
cin >> n >> k;
flag = 0;
for (i = 0; i < n / 2; i++)
cin >> arr1[i];
for (; i < n ; i++)
cin >> arr2[i];
recursive_generate(0, 0);
find_and_recursive2(0, n / 2);
if (flag == 1 )
cout << "Case " << cases - t << ": " << "Yes" << endl;
else
cout << "Case " << cases - t << ": " << "No" << endl;
}
return 0;
}