Raslboyy

212

Sep 5th, 2019
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <climits>
  6.  
  7. using namespace std;
  8.  
  9. int main() {
  10.     ifstream fin("input.txt");
  11.     ofstream fout("output.txt");
  12.  
  13.     int n;
  14.     fin >> n;
  15.     vector<int> dp(n, INT_MAX);
  16.     vector<int> coast(3);
  17.     fin >> dp[0] >> dp[1] >> dp[2];
  18.     for (int i = 1; i < n; i++) {
  19.         fin >> coast[0] >> coast[1] >> coast[2];
  20.         for (int j = i; j < i + 3 && j < n; j++)
  21.             dp[j] = min(dp[j], dp[i - 1] + coast[j-i]);
  22.     }
  23.     fout << dp[n - 1] << endl;
  24.  
  25.     fin.close();
  26.     fout.close();
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment