很好想的线性p
#include<bits/stdc++.h>
using namespace std;
void solve(){
int n;
cin>>n;
vector<int>a(n+1);
vector<int>dp(n+1,1e18);
dp[1]=0;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=2;i<=n;i++){
dp[i]=min(dp[i],dp[i-1]+abs(a[i]-a[i-1]));
if(i!=2)dp[i]=min(dp[i],dp[i-2]+abs(a[i]-a[i-2]));
}
cout<<dp[n];
}
int main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)solve();
return 0;
}
标签:std,1e18,int,vectordp,void,Frog
From: https://www.cnblogs.com/yufan1102/p/17924274.html