-
Notifications
You must be signed in to change notification settings - Fork 0
/
10344-23_Out_of_5.cpp
79 lines (54 loc) · 984 Bytes
/
10344-23_Out_of_5.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include<bits/stdc++.h>
using namespace std;
const int maxn=7;
const int n=5;
int a[maxn];
bool flag[maxn], solved;
void back_tracking(int res, int k)
{
if(solved)
return;
if(res==23 and k>n)
{
solved=true;
return;
}
for(int i=1; i<=n; i++)
{
if(flag[i])
{
flag[i]=false;
back_tracking(res+a[i], k+1);
back_tracking(res-a[i], k+1);
back_tracking(res*a[i], k+1);
flag[i]=true;
}
}
}
int main()
{
// freopen("/home/ornob/Downloads/Practice/input.txt", "r", stdin);
// freopen("/home/ornob/Downloads/Practice/output.txt", "w", stdout);
while(1)
{
for(int i=1; i<=n; i++)
cin>>a[i];
if(a[0]==0 && a[1]==0 && a[2]==0 && a[3]==0 && a[4]==0)
break;
solved=false;
memset(flag, true, sizeof(flag));
for(int i=1; i<=n; i++)
{
flag[i]=false;
back_tracking(a[i], 2);
flag[i]=true;
if(solved)
break;
}
if(solved)
cout<<"Possible"<<endl;
else
cout<<"Impossible"<<endl;
}
return 0;
}