Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int n;
- int niza[100005];
- int dp[100005];
- int jump(int i) {
- if(i == n - 1) {
- return 0;
- }
- if(dp[i] != -1) {
- return dp[i];
- }
- int result = 2e9;
- result = min(result, jump(i + 1) + abs(niza[i] - niza[i + 1]));
- if(i + 2 < n) {
- result = min(result, jump(i + 2) + abs(niza[i] - niza[i + 2]));
- }
- dp[i] = result;
- return result;
- }
- int main() {
- cin >> n;
- for(int i = 0; i < n; i++) {
- cin >> niza[i];
- dp[i] = -1;
- }
- cout << jump(0) << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement