考虑上一层还是上两层还是爬上去
#include <bits/stdc++.h>
using namespace std;
int f[1000005],a[1000005];
int main() {
int n; scanf("%d",&n);
for (int i=1;i<=n;i++) scanf("%d",&a[i]);
for (int i=1;i<=n;i++) f[i]=min(f[i-1]+a[i],min(f[i-2]+a[i-1],f[i-3]+a[i-2]));
printf("%d\n",f[n]);
return 0;
}
原文:https://www.cnblogs.com/Dawn-Star/p/9846504.html