#include <iostream> #include <climits> using namespace std; long long h[51],b[51]={1}; int n,f[51]; int main() { cin>>n; for (int i=1;i<=n;++i){ cin>>h[i]; b[i]=b[i-1]<<1; } for (int i=2;i<=n;++i){ f[i]=INT_MAX/3; for (int j=1;j<i;++j) for (int k=j;k>0;--k) if (b[j-k]+h[k]>=h[i]) f[i]=min(f[j]+j-k+1,f[i]); if (f[i]==INT_MAX/3){ cout<<-1; return 0; } //cout<<i<<'='<<f[i]<<endl; } cout<<f[n]; return 0; }
7
7
2015
7
2015