-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMARCHA1.cpp
157 lines (125 loc) · 2.71 KB
/
MARCHA1.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
@uthor: abhishekMadhu
handle: coder_nigga
UEM,KOLKATA
*/
/*
//unsolved and incomplete
//MARCHA1 for 2009
//https://www.codechef.com/problems/MARCHA1
*/
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define X first
#define Y second
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define FILL(a,x) memset(a,x,sizeof(a))
#define foreach( gg,itit ) for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
#define mp make_pair
#define pb push_back
#define all(s) s.begin(),s.end()
#define present(c,x) ((c).find(x) != (c).end())
const double EPS = 1e-8;
const int mod = 1e9+7;
const int N = 1e6+10;
const ll INF = 1e18;
bool jBitNotSet(int j, int n)
{
return ((n>>j)%2);
}
int main()
{
int t,n,m,flag,sum,i,j,a[30];
cin>>t;
while(t--)
{
flag = 0;
cin>>n>>m;
for(i=1; i<=n; i++)
{
cin>>a[i];
}
for(i=1; i<=pow(2,n); i++)
{
sum = 0;
for(j=0 ; j<n; j++)
{
if(!jBitNotSet(j,i))
{
sum += a[j];
}
if (sum == m)
{
cout<<"Yes\n";
flag = -1;
break;
}
}
}
if(flag == 0)
cout<<"No\n";
}
return 0;
}
/*int main()
{
int t,n,m,p[10010] = {0}, chef[10010]={0},assistant[10010] = {0}, j, x, y, k;
cin>>t;
while(t--)
{
cin>>n>>m;
for (int i=1; i<=m; i++)
{
cin>>k;
p[k]=-1;
}
j=1;
x=1;
y=1;
for(int i=1; i<=n; i++)
{
if(p[i]==0)
{
if(j%2==1)
{
chef[x]=i;
x++;
}
else
{
assistant[y] = i;
y++;
}
}
}
for(int i=1; i<=x; i++)
cout<<chef[i]<<" ";
cout<<endl;
for(int i=1; i<=y; i++)
cout<<assistant[i]<<" ";
cout<<endl;
/*
sort(q,q+m-n);
for(int i=0; i<n-m; i++)
{
if(i%2==0)
printf("%d ", q[i]);
}
printf("\n");
for(int i=0; i<n-m; i++)
{
if(i%2==1)
printf("%d ", q[i]);
}
cout<<endl;
*//*
}
return 0;
}
*/