Guest User

Untitled

a guest
Jul 17th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. class Solution {
  2. public:
  3. int minRefuelStops(int target, int startFuel, vector<vector<int>>& stations) {
  4. int len = stations.size();
  5. vector<long> dp(len + 1, 0);
  6. dp[0] = startFuel;
  7. for (int i = 0; i < len; ++i)
  8. {
  9. for (int j = i + 1; j > 0; --j)
  10. {
  11. if (dp[j - 1] >= stations[i][0])
  12. dp[j] = max(dp[j], dp[j - 1] + static_cast<long>(stations[i][1]));
  13. }
  14. }
  15. for (int i = 0; i <= len; ++i)
  16. if (dp[i] >= target)return i;
  17. return -1;
  18. }
  19. };
Add Comment
Please, Sign In to add comment