From c026afeb33ede5e808e6f94ef351d971e5da1e9a Mon Sep 17 00:00:00 2001 From: Deepti Singh <43244026+iamdeepti@users.noreply.github.com> Date: Tue, 12 Feb 2019 20:03:40 +0530 Subject: [PATCH] Update Sherlock and cost.cpp --- sherlock-and-cost.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sherlock-and-cost.cpp b/sherlock-and-cost.cpp index b591def..9b9f704 100644 --- a/sherlock-and-cost.cpp +++ b/sherlock-and-cost.cpp @@ -20,9 +20,9 @@ int main() for (int i = 1; i < n; i++) { dp[i][0] = max(dp[i - 1][0], dp[i - 1][1] + abs(b[i - 1] - 1)); - dp[i][1] = max(dp[i - 1][0] + abs(b[i] - 1), dp[i - 1][1]); + dp[i][1] = max(dp[i - 1][0] + abs(b[i] - 1), dp[i - 1][1] + abs(b[i] - b[i-1])); } cout << max(dp[n - 1][0], dp[n - 1][1]) << endl; } return 0; -} \ No newline at end of file +}