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