Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- bool flag;
- int arr[7];
- void solve(int index,int val)
- {
- if(index==5 && val==23)
- {
- flag = true;
- return;
- }
- if(index>=5)
- return;
- solve(index+1,val+arr[index]);
- solve(index+1,val-arr[index]);
- solve(index+1,val*arr[index]);
- }
- int main()
- {
- int i;
- while(scanf("%d",&arr[0])&&arr[0])
- {
- for(i=1;i<5;i++)
- {
- scanf("%d",&arr[i]);
- }
- sort(arr,arr+5);
- flag = false;
- solve(1,arr[0]);
- while(!flag && next_permutation(arr,arr+5))
- {
- solve(1,arr[0]);
- }
- if(flag)
- {
- printf("Possible\n");
- }
- else
- {
- printf("Impossible\n");
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment