Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Task : Cartoon
- Author : Phumipat C. [MAGCARI]
- Language: C++
- Created : 24 October 2022 [19:58]
- */
- #include<bits/stdc++.h>
- using namespace std;
- int a[1010];
- int n,k;
- bool ans;
- void recurse(int state,int res){
- if(state == n){
- if(res == k)
- ans = true;
- return ;
- }
- recurse(state+1,res+a[state+1]);
- recurse(state+1,res-a[state+1]);
- recurse(state+1,res*a[state+1]);
- recurse(state+1,res/a[state+1]);
- }
- int main(){
- cin.tie(0)->sync_with_stdio(0);
- cin.exceptions(cin.failbit);
- int q;
- cin >> q;
- while(q--){
- cin >> n >> k;
- for(int i=1;i<=n;i++)
- cin >> a[i];
- ans = false;
- recurse(1,a[1]);
- if(ans) cout << "YES\n";
- else cout << "NO\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment