Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main( )
- {
- int n;
- cin >> n;
- int A[n], B[n], C[n], d[n];
- for (int i = 0; i < n; ++i)
- {
- cin >> A[i] >> B[i] >> C[i];
- if (i == 0)
- d[i] = A[i];
- else if (i == 1)
- d[i] = min(A[i - 1] + A[i], B[i - 1]);
- else
- d[i] = min(d[i - 1] + A[i],
- min(((i - 3 >= 0) ? d[i - 3] : 0) + C[i - 2],
- min(d[i - 2] + B[i - 1], A[i] + ((i - 3 >= 0) ? d[i - 3] : 0) + B[i - 2])));
- }
- cout << d[n-1];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment