Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int A[5], vis[5], vis2[5], per[5];
- bool possible = false;
- void solve2(int ans)
- {
- bool f = false;
- for(int i=1; i<5; i++)
- if(!vis[i])
- f = true;
- if(!f)
- if(ans==23)
- possible = true;
- if(!possible)
- {
- for(int i=1; i<5; i++)
- {
- if(!vis[i])
- {
- vis[i] = true;
- solve2(ans+per[i]);
- solve2(ans*per[i]);
- solve2(ans-per[i]);
- vis[i] = false;
- }
- }
- }
- }
- void solve(int k)
- {
- if(!possible)
- {
- if(k==5)
- solve2(per[0]);
- for(int i=0; i<5; i++)
- {
- if(!vis2[i])
- {
- vis2[i] = true;
- per[k] = A[i];
- solve(k+1);
- vis2[i] = false;
- }
- }
- }
- }
- int main()
- {
- bool output[27]; int op;
- for(int i=0; i<27; i++)
- {
- bool f = false;
- for(int j=0; j<5; j++)
- {
- cin >> A[j];
- if(A[j]!=0)
- f = true;
- }
- if(!f)
- {
- op = i;
- break;
- }
- solve(0);
- if(possible)
- output[i] = true;
- else
- output[i] = false;
- possible = false;
- }
- for(int i=0; i<op; i++)
- {
- if(output[i])
- cout << "Possible" << endl;
- else
- cout << "Impossible" << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement