【ZJOI2005】午餐
作者:互联网
题面
https://www.luogu.org/problem/P2577
题解
#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> using namespace std; struct node{ int a,b; bool operator < (const node &rhs) const { return b>rhs.b; } } t[250]; const int inf=98765; int n,ans=inf; int f[205][40250],sum[205]; int dp(int x,int y) { if (x>=0&&y>=0 && y<=sum[x]) return f[x][y]; else return inf; } int main() { int i,j; scanf("%d",&n); sum[0]=0; for (i=1;i<=n;i++) { scanf("%d %d",&t[i].a,&t[i].b); } sort(t+1,t+n+1); for (i=1;i<=n;i++) sum[i]=sum[i-1]+t[i].a; memset(f,0x3f,sizeof(f)); f[0][0]=0; for (i=1;i<=n;i++) { for (j=0;j<=sum[i];j++) f[i][j]=min(max(dp(i-1,j-t[i].a),j+t[i].b),max(dp(i-1,j),sum[i]-j+t[i].b)); } ans=inf; for (i=0;i<=sum[n];i++) ans=min(ans,f[n][i]); cout<<ans<<endl; }
标签:ZJOI2005,const,int,午餐,205,inf,include,rhs 来源: https://www.cnblogs.com/shxnb666/p/11427298.html