标签:问题: 计划 假设 pac sum 分析 sizeof etc eof
\[ dp[i][j]= \left\{ \begin{array}{rcl} min(max(dp[i-1][j-p[i].a],j+p[i].b),max(dp[i-1][j],k+p[i].b)) & j,k>=a[i]\max(dp[i-1][j-p[i].a],j+p[i].b) & j>=a[i]\max(dp[i-1][j],k+p[i].b) & k>=a[i] \end{array}\right. \]
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#define maxn 201
#define maxm 40001
#define inf 0x3f3f3f3f
using namespace std;
inline int read(){
register int x(0),f(1); register char c(getchar());
while(c<'0'||'9'<c){ if(c=='-') f=-1; c=getchar(); }
while('0'<=c&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
struct node{ int a,b; }p[maxn];
int dp[maxn][maxm];
int n,c[maxn];
inline bool cmp(const node &x,const node &y){ return x.b>y.b; }
int main(){
n=read();
for(register int i=1;i<=n;i++) p[i].a=read(),p[i].b=read();
sort(p+1,p+1+n,cmp);
for(register int i=1;i<=n;i++) c[i]=c[i-1]+p[i].a;
memset(dp,0x3f,sizeof dp),dp[0][0]=0;
for(register int i=1;i<=n;i++){
for(register int j=0;j<=c[i];j++){
register int k=c[i]-j;
if(j>=p[i].a && k>=p[i].a) dp[i][j]=min( max( dp[i-1][j-p[i].a],j+p[i].b ),max( dp[i-1][j],k+p[i].b ) );
else if(j>=p[i].a) dp[i][j]=max( dp[i-1][j-p[i].a],j+p[i].b );
else if(k>=p[i].a) dp[i][j]=max( dp[i-1][j],k+p[i].b );
}
}
int ans=inf;
for(register int i=0;i<=c[n];i++) ans=min( ans,dp[n][i] );
printf("%d\n",ans);
return 0;
}
标签:问题: 计划 假设 pac sum 分析 sizeof etc eof
原文地址:https://www.cnblogs.com/akura/p/11287014.html