int DAC(int l,int r,int cost){
if(r-l<=2||cost<0) return 0;
int ans=0;
for(int i=l+1;i<=r-2;i+=2){
int temp=0;
if(pre[i]-pre[l-1]==(i-l+1)>>1&&(cost-abs(a[i+1]-a[i])>=0)){
int num1=DAC(l,i,cost-abs(a[i+1]-a[i]));
int num2=DAC(i+1,r,cost-abs(a[i+1]-a[i]));
temp=num1+num2+1;
cout<<l<<" "<<r<<" at "<<i<<" with value "<<temp<<endl;
ans=max(ans,temp);
}
}
return ans;
}
一个失败的递归!因为两个子问题是互相影响的,引以为戒!!