Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <string>
  5. #include <stack>
  6.  
  7. using namespace std;
  8. using std::string;
  9.  
  10. vector <string> words;
  11. stack <int> res;
  12. int dict_len, a[1000][1000];
  13. bool happy_end;
  14.  
  15. void parse(int st, int en, int row)
  16. {
  17. bool profit = false;
  18.  
  19. if (!happy_end)
  20. {
  21. for (int i = st; i <= en && !happy_end; i++)
  22. if (a[i][row] != -1)
  23. {
  24. profit = true;
  25. res.push(a[i][row]);
  26. if (i == en)
  27. {
  28. happy_end = true;
  29. break;
  30. }
  31. else
  32. parse(i + 1, en, row + i - st + 1);
  33. }
  34.  
  35. if (!profit) res.pop();
  36. }
  37. }
  38.  
  39. bool can[1000];
  40. int how[1000];
  41. int main()
  42. {
  43. string base, ts;
  44. int i, j, pos;
  45.  
  46.  
  47. cin >> base >> dict_len;
  48. can[0] = true;
  49. how[0] = -1;
  50. for (int i = 0; i < base.size(); i++)
  51. if (can[i])
  52. for (int j = 0; j < words.size(); j++)
  53. if (base.substr(i, words[j].size()) == words[j])
  54. {
  55. can[i + words[j].size()] = true;
  56. how[i + words[j].size()] = j;
  57. }
  58. pos = base.size();
  59. vector<int> ans;
  60. while (pos > 0)
  61. {
  62. ans.push_back(how[pos]);
  63. pos -= words[how[pos]].size();
  64. }
  65. for (int i = ans.size() - 1; i >= 0; i--)
  66. cout << words[ans[i]] << ' ';
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement