真的好变态的DP啊,死想想不出来,记住了这道变态dp
#include<stdio.h>
#include<cstring>
#include<algorithm>
using namespace std;
#define M 105
#define MAX 505
int n,w[3],s[3],d[3],c[3],d4,x[M],y[M],dp[2][MAX][MAX],a,b;
void func(){
int p,q,i,j,t,maxx=0,maxy=0,tmp,tmpx,tmpy,tmpz;
for(t=1;t<=n;t++){
memset(dp[t%2],-1,sizeof(dp[t%2]));
a=x[t]/w[0]; b=y[t]/s[0]; tmpx=a<b?a:b;
for(i=0;i<=tmpx;i++){
a=(x[t]-w[0]*i)/w[1]; b=(y[t]-s[0]*i)/s[1];
tmpy=a<b?a:b;
if(i==0)tmp=tmpy;
for(j=0;j<=tmpy;j++){
a=(x[t]-w[0]*i-w[1]*j)/w[2];
b=(y[t]-s[0]*i-s[1]*j)/s[2]; tmpz=a<b?a:b;
for(p=0;p<=maxx;p++)
for(q=0;q<=maxy;q++)
if(dp[(t+1)%2][p][q]!=-1){
a=dp[t%2][p+i][q+j];
b=dp[(t+1)%2][p][q]+tmpz;
dp[t%2][p+i][q+j]=a>b?a:b;
}
}
}
maxx+=tmpx;
maxy+=tmp;
}
int rst=0,def=max(0,d4-c[0]*d[0]-c[1]*d[1]-c[2]*d[2]);
for(i=0;i<=maxx;i++)
for(j=0;j<=maxy;j++)
if(dp[(t+1)%2][i][j]!=-1){
tmp=min(i/c[0],j/c[1]);
tmp=min(tmp,dp[(t+1)%2][i][j]/c[2]);
a=i*d[0]+j*d[1]+dp[(t+1)%2][i][j]*d[2]+def*tmp;
rst=a>rst?a:rst;
}
printf("%d\n",rst);
}
int main(){
int i,cas=0;
while(scanf("%d",&n),n){
for(i=0;i<3;i++)
scanf("%d %d %d",&w[i],&s[i],&d[i]);
for(i=0;i<3;i++)
scanf("%d",&c[i]);
scanf("%d",&d4);
for(i=1;i<=n;i++)
scanf("%d %d",&x[i],&y[i]);
memset(dp[0],0,sizeof(dp[0]));
if(cas>0)printf("\n");
printf("Case %d: ",++cas);
func();
}
return 0;
}