内容目录
注意不能往西跳(一开始以为可以,看题仔细啊!)
#include<cstdio> #include<iostream> #include<cstdlib> #include<cstring> #include<cmath> #include<functional> #include<algorithm> #include<cctype> using namespace std; #define MAXN (100000+10) #define MAXHi (10000+10) int n,h[MAXN]; int main() { cin>>n; for (int i=1;i<=n;i++) cin>>h[i];h[0]=1; int ans=0; for (int i=1;i<=n;i++) ans+=abs(h[i]-h[i-1]); /* int hmin=h[n]; for (int i=n-1;i>=1;i--) { ans=min(ans,ans-abs(h[i]-h[i-1])-abs(h[i+1]-h[i])+abs(h[i-1]-h[i+1])+n-i+abs(hmin-h[i])+abs(hmin-h[n])); } */ ans+=2*n; cout<<ans<<endl; return 0; }