You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
669 B
23 lines
669 B
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
const int N = 1000010;
|
|
//递推法
|
|
int n, a[N];
|
|
int f[N]; //代表前i个区域被填充好的最少次数.套路,满满的套路
|
|
|
|
int main() {
|
|
cin >> n;
|
|
for (int i = 1; i <= n; i++) cin >> a[i];
|
|
//递推出口,第一个有多大的坑,不能指望别人,都要靠自己来完成~
|
|
f[1] = a[1];
|
|
//从第2个开始进行递推
|
|
for (int i = 2; i <= n; i++) {
|
|
//递推式:见题解的分析过程
|
|
if (a[i] <= a[i - 1]) f[i] = f[i - 1];
|
|
else f[i] = f[i - 1] + (a[i] - a[i - 1]);
|
|
}
|
|
//输出大吉
|
|
cout << f[n] << endl;
|
|
return 0;
|
|
} |