思路非常巧妙啊
code:
#include <cstdio>
#include <algorithm>
#define ll long long
#define N 5003
#define setIO(s) freopen(s".in","r",stdin)
using namespace std;
int f[N][N],h[N],n;
double slope(int l,int r){return (double)(h[r]-h[l])/(r-l);}
bool cansee(int l,int x,int r){return slope(x,r)>slope(l,r);}
int main()
{
// setIO("input");
int i,j,ans=0;
scanf("%d",&n);
for(i=1;i<=n;++i) scanf("%d",&h[i]);
for(int r=1;r<=n;++r)
{
f[r][r]=1;
ans^=f[r][r];
int sum=1,p=0;
for(int l=r-1;l>=1;--l)
{
if(!p||cansee(l,p,r))
{
sum+=min(f[l+1][p-1],f[l+1][p]);
p=l;
}
f[l][r]=sum+min(f[l][p],f[l][p-1]);
ans^=f[l][r];
}
}
printf("%d\n",ans);
return 0;
}