#include <bits/stdc++.h>
using namespace std;
vector <int> numbers;
int flag, visited[7];
void call(int curr, int sum){
if(sum == 23 && curr == 5){
printf("Possible\n");
flag = 1;
return;
}
for(int index = 0; index < 5; index++){
if(flag)break;
if(!visited[index]){
visited[index] = 1;
call(curr+1, sum+numbers[index]);
call(curr+1, sum-numbers[index]);
call(curr+1, sum*numbers[index]);
visited[index] = 0;
}
}
}
int main(){
int n, f = 0;
while(1){
for(int i = 0; i < 5; i++){
scanf("%d", &n), numbers.push_back(n);
if(n == 0)f++;
}
if(f == 5)break;
memset(visited, 0, sizeof(visited));
flag = 0;
for(int i = 0; i < 5; i++){
visited[i] = 1;
call(1, numbers[i]);
visited[i] = 0;
}
if(!flag)printf("Impossible\n");
numbers.clear();
}
return 0;
}
using namespace std;
vector <int> numbers;
int flag, visited[7];
void call(int curr, int sum){
if(sum == 23 && curr == 5){
printf("Possible\n");
flag = 1;
return;
}
for(int index = 0; index < 5; index++){
if(flag)break;
if(!visited[index]){
visited[index] = 1;
call(curr+1, sum+numbers[index]);
call(curr+1, sum-numbers[index]);
call(curr+1, sum*numbers[index]);
visited[index] = 0;
}
}
}
int main(){
int n, f = 0;
while(1){
for(int i = 0; i < 5; i++){
scanf("%d", &n), numbers.push_back(n);
if(n == 0)f++;
}
if(f == 5)break;
memset(visited, 0, sizeof(visited));
flag = 0;
for(int i = 0; i < 5; i++){
visited[i] = 1;
call(1, numbers[i]);
visited[i] = 0;
}
if(!flag)printf("Impossible\n");
numbers.clear();
}
return 0;
}
No comments:
Post a Comment