Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- using namespace std;
- int main(){
- int n;
- int arr[5001][3], res[5002];
- scanf("%d", &n);
- for (int i = 0; i < n; i++){
- scanf("%d %d %d", &arr[i][0], &arr[i][1], &arr[i][2]);
- }
- for (int i = 0; i < n; i++){
- for (int j = 1; j <= 3 && i + j <= n; j++){
- if (!res[i + j] || res[i + j] > res[i] + arr[i][j - 1]){
- res[i + j] = res[i] + arr[i][j - 1];
- }
- }
- }
- printf("%d", res[n]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement