#include #include #include #include #include using namespace std; class Game { public: string Stones(int P, vector &S); vector Cache; }; string Game::Stones(int P, vector &S) { int i; /* If the cache is empty, create it. */ if (Cache.size() == 0) Cache.resize(P+1, ""); /* Get the return value from the cache if it's there. */ if (Cache[P] != "") return Cache[P]; /* Otherwise, use recursion to see if there is any value of s that will enable the caller to win. */ for (i = 0; i < S.size(); i++) { if (P-S[i] >= 0 && Stones(P-S[i], S) == "Lose") { Cache[P] = "Win"; return "Win"; } } /* If there is no such value, return that you are losing. */ Cache[P] = "Lose"; return "Lose"; } /* Here's a main that lets you test it. */ int main() { int P; int s; vector S; Game G; cin >> P; while (cin >> s) S.push_back(s); cout << G.Stones(P, S) << endl; }