Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <algorithm>
- #include <climits>
- using namespace std;
- int main() {
- ifstream fin("input.txt");
- ofstream fout("output.txt");
- int n;
- fin >> n;
- vector<int> dp(n, INT_MAX);
- vector<int> coast(3);
- fin >> dp[0] >> dp[1] >> dp[2];
- for (int i = 1; i < n; i++) {
- fin >> coast[0] >> coast[1] >> coast[2];
- for (int j = i; j < i + 3 && j < n; j++)
- dp[j] = min(dp[j], dp[i - 1] + coast[j-i]);
- }
- fout << dp[n - 1] << endl;
- fin.close();
- fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment