Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- ios_base::sync_with_stdio(true);
- int n;
- cin>>n;
- int x[n];
- int dp[n];
- memset(dp,0,sizeof dp);
- for(int i=0;i<n;i++)cin>>x[i];
- dp[0]=0;
- dp[1]=abs(x[0]-x[1]);
- for(int i=2;i<n;i++)
- {
- dp[i]=min(dp[i-1]+abs(x[i-1]-x[i]), dp[i-2]+abs(x[i-2]-x[i]));
- }
- cout<<dp[n-1];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement