class pro{
public static void main(String args[]){
int s1,s2;
double p1,p2,cost1,cost2,beta1,beta2,c;
double x1,x2;
double u1,w1,v1,v2,z1,r1,r2;
double maxr,max1,max2,maxc,maxv;
int j,n,n1,n2,n3,n4,n5;
int nx1,nx2,nx3,nx4,nx5;
int nxs1,nxs2,nxs3,nxs4,nxs5;
double th1[]=new double[6];
double th2[]=new double[6];
double p[][]=new double[6][6];
double q1[][]=new double[6][6];
double q2[][]=new double[6][6];
double ux[][][]=new double[6][6][3];
double wx[][][]=new double[6][6][3];
double zx[][][]=new double[6][6][3];
double rev[][][]=new double[6][6][3];
double v[][][][][][]=new double[6][3][3][3][3][3];
int goto1[][][][][][]=new int[6][3][3][3][3][3];
int goto2[][][][][][]=new int[6][3][3][3][3][3];
int goto3[][][][][][]=new int[6][3][3][3][3][3];
int goto4[][][][][][]=new int[6][3][3][3][3][3];
int goto5[][][][][][]=new int[6][3][3][3][3][3];
double h;
for (s1=1;s1<6;s1++){
th1[s1]=s1;
}
for (s2=1;s2<6;s2++){
th2[s2]=s2;
}
beta1=1;
beta2=1;
cost1=2;
cost2=2;
maxr=0;
maxc=0;
max1=0;
max2=0;
for (n1=1;n1<60;n1++){
for (n2=1;n2<60;n2++){
for (n3=1;n3<60;n3++){
p1=0.1*n1;
p2=0.1*n2;
c=0.1*n3;
r2=0;
for (s1=1;s1<6;s1++){
for (s2=1;s2<6;s2++){
x1=(th1[s1]-p1)/beta1;
if (x1<0)x1=0;
x2=(th2[s2]-p2)/beta2;
if (x2<0)x2=0;
u1=th1[s1]*x1+th2[s2]*x2-0.5*beta1*x1*x1-0.5*beta2*x2*x2-c;
if (u1<0)x1=0;
if (u1<0)x2=0;
r1=(p1-cost1)*x1+(p2-cost2)*x2+c;
j=0;
if (x1==0)j=j+1;
if (x2==0)j=j+1;
if (j==2)r1=0;
r2=r2+r1;
}
}
if (r2>maxr)maxc=c;
if (r2>maxr)max1=p1;
if (r2>maxr)max2=p2;
if (r2>maxr)maxr=r2;
}
}
}
System.out.println(maxc);
System.out.println(max1);
System.out.println(max2);
System.out.println(maxr);
p1=max1;
p2=max2;
c=maxc;
for (s1=1;s1<6;s1++){
for (s2=1;s2<6;s2++){
x1=(th1[s1]-p1)/beta1;
if (x1<0)x1=0;
x2=(th2[s2]-p2)/beta2;
if (x2<0)x2=0;
u1=th1[s1]*x1+th2[s2]*x2-0.5*beta1*x1*x1-0.5*beta2*x2*x2-c;
if (u1<0)x1=0;
if (u1<0)x2=0;
r1=(p1-cost1)*x1+(p2-cost2)*x2+c;
j=0;
if (x1==0)j=j+1;
if (x2==0)j=j+1;
if (j==2)r1=0;
q1[s1][s2]=x1;
q2[s1][s2]=x2;
r1=p1*x1+p2*x2+c;
if (j==2)r1=0;
p[s1][s2]=r1;
}
}
h=0.01;
for (s1=1;s1<6;s1++){
for (s2=1;s2<6;s2++){
for (n=-1;n<2;n++){
p1=p[s1][s2]+n*h;
x1=q1[s1][s2];
x2=q2[s1][s2];
u1=th1[s1]*x1+th2[s2]*x2-0.5*beta1*x1*x1-0.5*beta2*x2*x2-p1;
if (x1<0)u1=-999;
if (x2<0)u1=-999;
if (u1<0)u1=-999;
ux[s1][s2][n+1]=u1;
}
}
}
for (s1=1;s1<5;s1++){
for (s2=1;s2<6;s2++){
for (n=-1;n<2;n++){
p1=p[s1][s2]+n*h;
x1=q1[s1][s2];
x2=q2[s1][s2];
u1=th1[s1+1]*x1+th2[s2]*x2-0.5*beta1*x1*x1-0.5*beta2*x2*x2-p1;
if (x1<0)u1=-999;
if (x2<0)u1=-999;
if (u1<0)u1=-999;
wx[s1][s2][n+1]=u1;
}
}
}
for (s1=1;s1<6;s1++){
for (s2=1;s2<5;s2++){
for (n=-1;n<2;n++){
p1=p[s1][s2]+n*h;
x1=q1[s1][s2];
x2=q2[s1][s2];
u1=th1[s1]*x1+th2[s2+1]*x2-0.5*beta1*x1*x1-0.5*beta2*x2*x2-p1;
if (x1<0)u1=-999;
if (x2<0)u1=-999;
if (u1<0)u1=-999;
zx[s1][s2][n+1]=u1;
}
}
}
for (s1=1;s1<6;s1++){
for (s2=1;s2<6;s2++){
for (n=-1;n<2;n++){
p1=p[s1][s2]+n*h;
x1=q1[s1][s2];
x2=q2[s1][s2];
r1=p1-cost1*x1-cost2*x2;
if (ux[s1][s2][n+1]<0)r1=-999;
rev[s1][s2][n+1]=r1;
}
}
}
for (n1=-1;n1<2;n1++){
for (n2=-1;n2<2;n2++){
for (n3=-1;n3<2;n3++){
for (n4=-1;n4<2;n4++){
for (n5=-1;n5<2;n5++){
r1=rev[1][1][n1+1];
r1=r1+rev[1][2][n2+1];
r1=r1+rev[1][3][n3+1];
r1=r1+rev[1][4][n4+1];
r1=r1+rev[1][5][n5+1];
v1=r1;
u1=ux[1][2][n2+1];
w1=zx[1][1][n1+1];
if (w1>u1)v1=-999;
u1=ux[1][3][n3+1];
w1=zx[1][2][n2+1];
if (w1>u1)v1=-999;
u1=ux[1][4][n4+1];
w1=zx[1][3][n3+1];
if (w1>u1)v1=-999;
u1=ux[1][5][n5+1];
w1=zx[1][4][n4+1];
if (w1>u1)v1=-999;
v[1][n1+1][n2+1][n3+1][n4+1][n5+1]=v1;
}
}
}
}
}
for (s1=2;s1<6;s1++){
for (n1=-1;n1<2;n1++){
for (n2=-1;n2<2;n2++){
for (n3=-1;n3<2;n3++){
for (n4=-1;n4<2;n4++){
for (n5=-1;n5<2;n5++){
r1=rev[s1][1][n1+1];
r1=r1+rev[s1][2][n2+1];
r1=r1+rev[s1][3][n3+1];
r1=r1+rev[s1][4][n4+1];
r1=r1+rev[s1][5][n5+1];
v1=r1;
u1=ux[s1][2][n2+1];
w1=zx[s1][1][n1+1];
if (w1>u1)v1=-999;
u1=ux[s1][3][n3+1];
w1=zx[s1][2][n2+1];
if (w1>u1)v1=-999;
u1=ux[s1][4][n4+1];
w1=zx[s1][3][n3+1];
if (w1>u1)v1=-999;
u1=ux[s1][5][n5+1];
w1=zx[s1][4][n4+1];
if (w1>u1)v1=-999;;
maxv=-999;
nxs1=0;
nxs2=0;
nxs3=0;
nxs4=0;
nxs5=0;
for (nx1=-1;nx1<2;nx1++){
for (nx2=-1;nx2<2;nx2++){
for (nx3=-1;nx3<2;nx3++){
for (nx4=-1;nx4<2;nx4++){
for (nx5=-1;nx5<2;nx5++){
v2=v1+v[s1-1][nx1+1][nx2+1][nx3+1][nx4+1][nx5+1];
u1=ux[s1][1][n1+1];
w1=wx[s1-1][1][nx1+1];
if (w1>u1)v2=-999;
u1=ux[s1][2][n2+1];
w1=wx[s1-1][2][nx2+1];
if (w1>u1)v2=-999;
u1=ux[s1][3][n3+1];
w1=wx[s1-1][3][nx3+1];
if (w1>u1)v2=-999;
u1=ux[s1][4][n4+1];
w1=wx[s1-1][4][nx4+1];
if (w1>u1)v2=-999;
u1=ux[s1][5][n5+1];
w1=wx[s1-1][5][nx5+1];
if (w1>u1)v2=-999;;
if (v2>maxv)nxs1=nx1;
if (v2>maxv)nxs2=nx2;
if (v2>maxv)nxs3=nx3;
if (v2>maxv)nxs4=nx4;
if (v2>maxv)nxs5=nx5;
if (v2>maxv)maxv=v2;
}
}
}
}
}
goto1[s1][n1+1][n2+1][n3+1][n4+1][n5+1]=nxs1;
goto2[s1][n1+1][n2+1][n3+1][n4+1][n5+1]=nxs2;
goto3[s1][n1+1][n2+1][n3+1][n4+1][n5+1]=nxs3;
goto4[s1][n1+1][n2+1][n3+1][n4+1][n5+1]=nxs4;
goto5[s1][n1+1][n2+1][n3+1][n4+1][n5+1]=nxs5;
v[s1][n1+1][n2+1][n3+1][n4+1][n5+1]=maxv;
}
}
}
}
}
}
maxv=-999;
for (n1=-1;n1<2;n1++){
for (n2=-1;n2<2;n2++){
for (n3=-1;n3<2;n3++){
for (n4=-1;n4<2;n4++){
for (n5=-1;n5<2;n5++){
v1=v[5][n1+1][n2+1][n3+1][n4+1][n5+1];
if (v1>maxv)maxv=v1;
}
}
}
}
}
System.out.println(maxv);
}
}
最終更新:2010年07月21日 18:24