#include<bits/stdc++.h> using namespace std; int a[2525], d[2525]; int main(){ int n; cin >> n; for(int i = 0; i < n; i++) cin >> a[i]; for(int i = 0; i < n; i++){ int last = a[i]; d[i] = max(d[i], d[i-1]); for(int j = i+1; j < n; j++){ last = a[j]-last; if(last < 0) break; if(!last) d[j] = d[i-1]+1; } } cout << n-d[n-1]; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter