Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define popcnt(a) __builtin_popcount(a)
- #define FastIO() ios::sync_with_stdio(false), cin.tie(0);
- #define IO() freopen("palindrome.in","rw",stdin)
- #define error(args...) \
- { \
- cerr<<"LINE "<<__LINE__; \
- string _s = #args; \
- replace(_s.begin(), _s.end(), ',', ' '); \
- stringstream _ss(_s); \
- istream_iterator<string> _it(_ss); \
- err(_it, args); \
- cerr<<endl; \
- }
- void err(istream_iterator<string> it)
- {
- }
- template <typename T, typename... Args>
- void err(istream_iterator<string> it, T a, Args... args)
- {
- cerr<<' '<< *it << " = " << a ;
- err(++it, args...);
- }
- typedef long long LL;
- const LL MOD = 1e9 + 7;
- const int N = 1e7+9, M = (1<<31), OO = 0x3f3f3f3f;
- int h[N],memo[N],n;
- int solve(int idx=0)
- {
- if(idx>=n) return OO;
- int &ret = memo[idx];
- if(~ret) return ret;
- ret = OO;
- return ret = min(ret,min(solve(idx+1)+ abs(h[idx]-h[idx+1]),solve(idx+2) + abs(h[idx]-h[idx+2]) ));
- }
- int main()
- {
- memset(memo,-1,sizeof memo);
- scanf("%d",&n);
- for(int i=0;i<n;++i) scanf("%d",h+i);
- printf("%d",solve());
- #ifdef _LOCAL_DEFINE
- cerr << (double)clock() * 1.0 / CLOCKS_PER_SEC << endl;
- #endif
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement