题意:
枚举23点,注意,数字也是可以枚举的,wa了一次
#include<stdio.h> #include<iostream> #include<sstream> #include<queue> #include<map> #include<memory.h> #include <math.h> #include<time.h> #include <stdlib.h> #include <algorithm> using namespace std; #define N 12 int vis[N]; int a[N]; int b[N]; int n; int final = 0; void dfs(int cur, int total) { if(cur == 5 && total == 23) { final = 1; return; } for(int i = 0; i < 5 && !final; i++) { if(vis[i]) continue; vis[i] = 1; if(cur != 0) { dfs(cur + 1, total - a[i]); dfs(cur + 1, total + a[i]); dfs(cur + 1, total * a[i]); } else { dfs(cur + 1, a[i]); } vis[i] = 0; } } int main(const int argc, char** argv) { freopen("d:\1.txt", "r", stdin); while (scanf("%d %d %d %d %d", a, a + 1, a + 2, a + 3, a + 4)) { if(a[0] || a[1] || a[3] || a[4]) { final = 0; memset(vis, 0, sizeof(vis)); dfs(0, 0); if(final) cout << "Possible" << endl; else cout << "Impossible" << endl; } else { return 0; } } return 0; }