-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheraseletter.cpp
More file actions
48 lines (37 loc) · 1.02 KB
/
eraseletter.cpp
File metadata and controls
48 lines (37 loc) · 1.02 KB
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
//http://community.topcoder.com/stat?c=problem_solution&cr=8355516&rd=14569&pm=11504
//Dynamic ProgramminDynamic Programmin
#include <algorithm>
#include <string>
#include <map>
using namespace std;
#define Size(x) (int(x.size()))
map<string, string> memo;
string worst(string word);
string best(string word) {
if(memo.count(word)) return memo[word];
if(word == "") return "";
string ret = "";
for(int k=0; k<Size(word); k++)
ret = max(ret, word.substr(0, k) + worst(word.substr(k+1)));
return memo[word] = ret;
}
string worst(string word) {
if(word == "") return "";
string ret = "~";
for(int k=0; k<Size(word); k++)
ret = min(ret, word.substr(0, k) + best(word.substr(k+1)));
return ret;
}
class SistersErasingLetters {
public:
string whoWins(string word) {
// !FDI
return best(word) > word ? "Camomile" : "Romashka";
}
};
int main()
{
SistersErasingLetters el;
string ret = el.whoWins("abcd");
return 0;
}