Skip to content

Instantly share code, notes, and snippets.

@run
Created October 27, 2014 23:54
Show Gist options
  • Save run/fe97294df33b486546e0 to your computer and use it in GitHub Desktop.
Save run/fe97294df33b486546e0 to your computer and use it in GitHub Desktop.
DFS
void dfs(int start, string &s,
vector<string> &tmp, vector<vector<string> > &result)
{
if (start == s.size()) {
result.push_back(tmp);
return ;
}
for (int i = start; i < s.size(); i++) {
tmp.push_back(s.substr(start, i-start+1));
dfs(i+1, s, tmp, result);
tmp.pop_back();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment