Untitled

mail@pastecode.io avatar
unknown
plain_text
4 years ago
605 B
5
Indexable
Never
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int tm[50005][3];
int dp[50005];
int n;
int min(int a, int b) {
	return a < b ? a : b;
}
int rec(int x) {
	if (x < 0) return 0;
	if (dp[x] != -1) return dp[x];
	int ans = rec(x - 1) + tm[x][0];
	if (x > 0)
		ans = min(ans, rec(x - 2) + tm[x - 1][1]);
	if (x > 1)
		ans = min(ans, rec(x - 3) + tm[x - 2][2]);
	return dp[x] = ans;
}

signed main() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
		scanf("%d%d%d", &(tm[i][0]), &(tm[i][1]), &(tm[i][2]));
	for (int i = 0; i < 50005; ++i)
		dp[i] = -1;
	printf("%d", rec(n - 1));
}