Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- vector<int> a(5);
- bool flag = false;
- // s: dau
- /*
- 0 -> +
- 1 -> -
- 2 -> *
- */
- // a: phan tu
- void calculate(string s){
- int ans = 0;
- if (s[0] == '0') ans = a[0] + a[1];
- if (s[0] == '1') ans = a[0] - a[1];
- if (s[0] == '2') ans = a[0] * a[1];
- for(int i=1;i<s.length();i++){
- if (s[i] == '0') ans += a[i+1];
- if (s[i] == '1') ans -= a[i+1];
- if (s[i] == '2') ans *= a[i+1];
- }
- if (ans == 23) flag = true;
- }
- void Try(string s, int n){
- if (n == s.length()){
- calculate(s);
- }
- else{
- Try(s+"0",n);
- Try(s+"1",n);
- Try(s+"2",n);
- }
- }
- void subprocess(){
- Try("",4);
- }
- void process(){
- flag = false;
- cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
- while(next_permutation(a.begin() , a.end())){
- subprocess();
- }
- if (flag) cout << "YES";
- else cout << "NO";
- cout << endl;
- }
- int main(){
- int T;
- cin >> T;
- while(T--) process();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement