#include #include #include #include using namespace std; #define N 71 #define M 31 #define Max 999999 int dp[N*M][N*M]; struct Book { int h, w; }; int cmp(Book x, Book y) { if(x.h!=y.h) return x.h>y.h; return x.w=0; j--) { for(k=noww; k>=0; k--) { if(dp[j][k]==Max) continue; if(noww-j-k<0) continue; int a=0; if(j==0) a=book[i].h; dp[j+book[i].w][k]=min(dp[j+book[i].w][k], dp[j][k]+a); a=0; if(k==0) a=book[i].h; dp[j][k+book[i].w]=min(dp[j][k+book[i].w], dp[j][k]+a); } } noww+=book[i].w; } int minnum=Max; for(j=1; j<=noww; j++) { for(k=1; k<=noww; k++) { if(dp[j][k]==Max) continue; if(sum-j-k<=0) continue; int maxw=max(j, k); maxw=max(maxw, sum-j-k); minnum=min(minnum, maxw*(dp[j][k]+book[1].h)); } } printf("%d\n", minnum); } }