简单回溯。要用到全排列。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int x[10];
bool ok=false;
void dfs(int pos,int res)
{
if(pos==6)
{
if(res==23)
ok=true;
return;
}
else
{
dfs(pos+1,res+x[pos]);
dfs(pos+1,res-x[pos]);
dfs(pos+1,res*x[pos]);
}
}
int main()
{
while(scanf("%d%d%d%d%d",&x[1],&x[2],&x[3],&x[4],&x[5])&&!(!x[1]&&!x[2]&&!x[3]&&!x[4]&&!x[5]))
{
sort(x+1,x+6);
ok=false;
do
{
dfs(2,x[1]);
if(ok) break;
}
while(next_permutation(x+1,x+6));
if(ok) puts("Possible");
else puts("Impossible");
}
return 0;
}