Uva--10344(暴力)
2014-07-15 12:12:31
题意&思路:不说啥了。
1 #include <cstdio> 2 #include <iostream> 3 #include <cstring> 4 using namespace std; 5 6 int s[5],flag; 7 8 void Dfs(int cur,int re){ 9 if(cur == 5){ 10 printf("%d\n",re); 11 if(re == 23) 12 flag = 1; 13 return; 14 } 15 if(!flag) 16 Dfs(cur + 1,re + s[cur]); 17 if(!flag) 18 Dfs(cur + 1,re - s[cur]); 19 if(!flag) 20 Dfs(cur + 1,re * s[cur]); 21 //if(!flag && re != 0) 22 // Dfs(cur + 1,re / s[cur]); 23 } 24 int main(){ 25 while(scanf("%d %d %d %d %d",&s[0],&s[1],&s[2],&s[3],&s[4]) == 5){ 26 flag = 0; 27 Dfs(1,s[0]); 28 if(flag) 29 printf("Possible\n"); 30 else 31 printf("Impossible\n"); 32 } 33 return 0; 34 }