MCPcopy Create free account
hub / github.com/E869120/math-algorithm-book / main

Function main

codes/cpp/Code_3_07_1.cpp:8–25  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6int N, H[100009], dp[100009];
7
8int main() {
9 // ����
10 cin >> N;
11 for (int i = 1; i <= N; i++) cin >> H[i];
12
13 // ���I�v��@ �� �����̏o��
14 for (int i = 1; i <= N; i++) {
15 if (i == 1) dp[i] = 0;
16 if (i == 2) dp[i] = abs(H[i - 1] - H[i]);
17 if (i >= 3) {
18 int v1 = dp[i - 1] + abs(H[i - 1] - H[i]); // 1 �‘O�̑��ꂩ��W�����v����Ƃ�
19 int v2 = dp[i - 2] + abs(H[i - 2] - H[i]); // 2 �‘O�̑��ꂩ��W�����v����Ƃ�
20 dp[i] = min(v1, v2);
21 }
22 }
23 cout << dp[N] << endl;
24 return 0;
25}

Callers

nothing calls this directly

Calls 1

minFunction · 0.85

Tested by

no test coverage detected