Open utterances-bot opened 2 years ago
https://luyencode.net/problem/DPRECLINE
Đây là lời giải của mình đã AC. Nếu bạn đã cố gắng mà chưa làm được thì có thể tham khảo lời giải của mình.
``` #include using namespace std; int n, a[1002], b[1002], f[1002][2]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i] >> b[i]; f[1][0] = a[1]; f[1][1] = b[1]; for (int i = 2; i <= n; ++i) { f[i][0] = a[i] + max(f[i - 1][0] + abs(b[i] - b[i - 1]), f[i - 1][1] + abs(b[i] - a[i - 1])); f[i][1] = b[i] + max(f[i - 1][0] + abs(a[i] - b[i - 1]), f[i - 1][1] + abs(a[i] - a[i - 1])); } cout << max(f[n][0], f[n][1]); return 0; } ```
Độ dài đường gấp khúc - Luyện Code Online
https://luyencode.net/problem/DPRECLINE