Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 5005;
- int n;
- long long a[N], b[N], c[N], dp[N];
- int main(){
- cin >> n;
- for (int i = 1; i <= n; i++) {
- cin >> a[i] >> b[i] >> c[i];
- }
- dp[1] = a[1];
- dp[2] = min(a[1] + a[2], b[1]);
- for (int i = 3; i <= n; i++) {
- long long first_value = a[i] + dp[i - 1];
- long long second_value = b[i - 1] + dp[i - 2];
- long long third_value = c[i - 2] + dp[i - 3];
- dp[i] = min(first_value, min(second_value, third_value));
- }
- cout << dp[n] << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment