You are viewing a single comment's thread. Return to all comments →
int cost(vector<int> B) { int n = sz(B); vvi dp(N,vi(2,0)); FOR(i,1,n){ dp[i][0] = max(dp[i-1][0],dp[i-1][1] + B[i-1]-1); dp[i][1] = max(dp[i-1][1] + abs(B[i-1]-B[i]), dp[i-1][0] + B[i]-1); } return max(dp[n-1][0],dp[n-1][1]); }
Seems like cookies are disabled on this browser, please enable them to open this website
Sherlock and Cost
You are viewing a single comment's thread. Return to all comments →
DP O(N) solution