Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #include <string>
- #include <stack>
- using namespace std;
- using std::string;
- vector <string> words;
- stack <int> res;
- int dict_len, a[1000][1000];
- bool happy_end;
- void parse(int st, int en, int row)
- {
- bool profit = false;
- if (!happy_end)
- {
- for (int i = st; i <= en && !happy_end; i++)
- if (a[i][row] != -1)
- {
- profit = true;
- res.push(a[i][row]);
- if (i == en)
- {
- happy_end = true;
- break;
- }
- else
- parse(i + 1, en, row + i - st + 1);
- }
- if (!profit) res.pop();
- }
- }
- bool can[1000];
- int how[1000];
- int main()
- {
- string base, ts;
- int i, j, pos;
- cin >> base >> dict_len;
- can[0] = true;
- how[0] = -1;
- for (int i = 0; i < base.size(); i++)
- if (can[i])
- for (int j = 0; j < words.size(); j++)
- if (base.substr(i, words[j].size()) == words[j])
- {
- can[i + words[j].size()] = true;
- how[i + words[j].size()] = j;
- }
- pos = base.size();
- vector<int> ans;
- while (pos > 0)
- {
- ans.push_back(how[pos]);
- pos -= words[how[pos]].size();
- }
- for (int i = ans.size() - 1; i >= 0; i--)
- cout << words[ans[i]] << ' ';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement