提交时间:2023-11-26 18:18:47

运行 ID: 112403

#include<bits/stdc++.h> using namespace std; int n,a[1001]; int dfs(int i,int sum){ if(i>n)return sum; return min(dfs(i+1,sum+a[i]),dfs(i+2,sum+a[i])); } int main(){ cin>>n; for(int i=1;i<=n;i++){ cin>>a[i]; } cout<<min(dfs(1,0),dfs(2,0)); return 0; }