思路:
//By SiriusRen#include#include #include using namespace std;int n,m,st=1,a[6666],b[6666],l,r,ans,vis[6666],Mid,tot,sum[6666];bool dfs(int x,int pos,int waste){ if(!x)return 1; if(waste+sum[Mid]>tot)return 0; bool flag=0; for(int i=pos;i<=m;i++) if(a[i]-b[x]>=0){ a[i]-=b[x]; if(a[i] a[m])n--; for(int i=1;i<=n;i++)sum[i]=sum[i-1]+b[i]; while(a[st] >1; if(dfs(Mid,1,0))ans=Mid,l=Mid+1; else r=Mid-1; } printf("%d\n",ans);}