-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathmain.cpp
47 lines (43 loc) · 904 Bytes
/
main.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
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
class Solution {
unordered_map<string, bool> memo;
public:
vector<string> generatePossibleNextMoves(string s) {
vector<string> ret;
for (int i = 0; i < s.size() - 1; i++) {
if (s[i] == '+' && s[i + 1] == '+'){
string ss = s;
ss[i] = '-';
ss[i + 1] = '-';
ret.push_back(ss);
}
}
return ret;
}
bool canWinNim(string s) {
if (memo.count(s) > 0) {
return memo[s];
}
for (string s2 : generatePossibleNextMoves(s)) {
if (!canWinNim(s2)) {
return true;
}
}
return memo[s] = false;
}
};
int main() {
Solution sol;
string start = "++++";
cout << sol.canWinNim(start) << endl;
return 0;
}