class pro{
public static void main(String args[]){
int m,mx,s1,s2,n1,n2,n3,n4,n5,n6;
int nx1,nx2,nx3,nx4,nx5,nx6;
int nxs1,nxs2,nxs3,nxs4,nxs5,nxs6;
double tk,tl,tr,ww,maxw,tks,tls,trs;
double th1[]=new double[11];
double th2[]=new double[11];
double c[][]=new double[11][3];
double y1[][]=new double[11][3];
double y2[][]=new double[11][3];
double ws1[][][][]=new double[11][3][3][3];
double ws2[][][][]=new double[11][3][3][3];
double u[][][][][][][]=new double[11][3][3][3][3][3][3];
double v[][][][][][][][]=new double[11][3][3][3][3][3][3][11];
int goto1[][][][][][][][]=new int[11][3][3][3][3][3][3][11];
int goto2[][][][][][][][]=new int[11][3][3][3][3][3][3][11];
int goto3[][][][][][][][]=new int[11][3][3][3][3][3][3][11];
int goto4[][][][][][][][]=new int[11][3][3][3][3][3][3][11];
int goto5[][][][][][][][]=new int[11][3][3][3][3][3][3][11];
int goto6[][][][][][][][]=new int[11][3][3][3][3][3][3][11];
int gotom[][][][][][][][]=new int[11][3][3][3][3][3][3][11];
double endv[][][][][][]=new double[3][3][3][3][3][3];
int end1[][][][][][]=new int[3][3][3][3][3][3];
int end2[][][][][][]=new int[3][3][3][3][3][3];
int end3[][][][][][]=new int[3][3][3][3][3][3];
int end4[][][][][][]=new int[3][3][3][3][3][3];
int end5[][][][][][]=new int[3][3][3][3][3][3];
int end6[][][][][][]=new int[3][3][3][3][3][3];
int endm[][][][][][]=new int[3][3][3][3][3][3];
int op1[][]=new int[11][3];
int op2[][]=new int[11][3];
int opc[][]=new int[11][3];
int t1,t2,t7;
double h,ux1,ux2;
double cp,yp1,yp2,cs,ys1,ys2;
double w1,w2,z1,u1,u2,v1,v2,v3,maxv,supv;
int max1,max2,max3,max4,max5,max6;
int p,p1,p2,px1,px2,px,mxs;
int sup1,sup2,d1,d2;
int j,e;
for (s1=1;s1<11;s1++){
th1[s1]=0.2*s1;
}
for (s2=1;s2<3;s2++){
th2[s2]=0.5*s2;
}
maxw=-999;
tks=0;
tls=0;
trs=0;
for (n1=5;n1<40;n1++){
for (n2=5;n2<40;n2++){
tk=0.01*n1;
tl=0.01*n2;
tr=trs(tk,tl,th1,th2);
ww=wel(tk,tl,tr,th1,th2);
if (ww>maxw)tks=tk;
if (ww>maxw)tls=tl;
if (ww>maxw)trs=tr;
if (ww>maxw)maxw=ww;
}
}
System.out.println(tks);
System.out.println(tls);
tk=tks;
tl=tls;
tr=trs;
for (s1=1;s1<11;s1++){
for (s2=1;s2<3;s2++){
y1[s1][s2]=th1[s1]*mlx(s1,s2,tk,tl,tr,th1,th2);
y2[s1][s2]=th2[s2]*flx(s1,s2,tk,tl,tr,th1,th2);
c[s1][s2]=(1-tk)*y1[s1][s2]+(1-tl)*y2[s1][s2]+tr;
}
}
h=0.001;
t2=0;
while(t2<10){
h=h/2;
t1=0;
while(t1<100){
for (s1=1;s1<11;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++){
for (n6=-1;n6<2;n6++){
cs=c[s1][1]+n3*h;
ys1=y1[s1][1]+n1*h;
ys2=y2[s1][1]+n2*h;
cp=c[s1][2]+n6*h;
yp1=y1[s1][2]+n4*h;
yp2=y2[s1][2]+n5*h;
u1=Math.log(cs)+Math.log(1-ys1/th1[s1])+Math.log(1-ys2/th2[1]);
w1=Math.log(cs)+Math.log(1-ys1/th1[s1])+Math.log(1-ys2/th2[2]);
u2=Math.log(cp)+Math.log(1-yp1/th1[s1])+Math.log(1-yp2/th2[2]);
if (w1>u2)u2=-999;
u[s1][n1+1][n2+1][n3+1][n4+1][n5+1][n6+1]=u1+u2;
}
}
}
}
}
}
}
for (s1=1;s1<10;s1++){
for (n1=-1;n1<2;n1++){
for (n2=-1;n2<2;n2++){
for (n3=-1;n3<2;n3++){
cs=c[s1][1]+n3*h;
ys1=y1[s1][1]+n1*h;
ys2=y2[s1][1]+n2*h;
u1=Math.log(cs)+Math.log(1-ys1/th1[s1+1])+Math.log(1-ys2/th2[1]);
ws1[s1][n1+1][n2+1][n3+1]=u1;
}
}
}
}
for (s1=1;s1<10;s1++){
for (n4=-1;n4<2;n4++){
for (n5=-1;n5<2;n5++){
for (n6=-1;n6<2;n6++){
cs=c[s1][2]+n6*h;
ys1=y1[s1][2]+n4*h;
ys2=y2[s1][2]+n5*h;
u1=Math.log(cs)+Math.log(1-ys1/th1[s1+1])+Math.log(1-ys2/th2[2]);
ws2[s1][n4+1][n5+1][n6+1]=u1;
}
}
}
}
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++){
for (n6=-1;n6<2;n6++){
for (m=-5;m<6;m++){
v[1][n1+1][n2+1][n3+1][n4+1][n5+1][n6+1][m+5]=-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++){
for (n6=-1;n6<2;n6++){
m=n1+n2+n4+n5-n3-n6;
u1=u[1][n1+1][n2+1][n3+1][n4+1][n5+1][n6+1];
px=0;
if (m>5)px=100;
if (m<-5)px=100;
if (px>50)m=0;
if (px>50)u1=-999;
v[1][n1+1][n2+1][n3+1][n4+1][n5+1][n6+1][m+5]=u1;
}
}
}
}
}
}
for (s1=2;s1<10;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++){
for (n6=-1;n6<2;n6++){
for (m=-5;m<6;m++){
u1=u[s1][n1+1][n2+1][n3+1][n4+1][n5+1][n6+1];
mx=m-n1-n2-n4-n5+n3+n6;
px=0;
if (mx>5)px=100;
if (mx<-5)px=100;
if (px>50)mx=0;
maxv=-999;
nxs1=0;
nxs2=0;
nxs3=0;
nxs4=0;
nxs5=0;
nxs6=0;
cs=c[s1][1]+n3*h;
ys1=y1[s1][1]+n1*h;
ys2=y2[s1][1]+n2*h;
ux1=Math.log(cs)+Math.log(1-ys1/th1[s1])+Math.log(1-ys2/th2[1]);
cs=c[s1][2]+n6*h;
ys1=y1[s1][2]+n4*h;
ys2=y2[s1][2]+n5*h;
ux2=Math.log(cs)+Math.log(1-ys1/th1[s1])+Math.log(1-ys2/th2[2]);
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++){
for (nx6=-1;nx6<2;nx6++){
v1=u1+v[s1-1][nx1+1][nx2+1][nx3+1][nx4+1][nx5+1][nx6+1][mx+5];
if(ws2[s1-1][nx4+1][nx5+1][nx6+1]>ux2)v1=-999;
if(ws1[s1-1][nx1+1][nx2+1][nx3+1]>ux1)v1=-999;
if (v1>maxv)nxs1=nx1;
if (v1>maxv)nxs2=nx2;
if (v1>maxv)nxs3=nx3;
if (v1>maxv)nxs4=nx4;
if (v1>maxv)nxs5=nx5;
if (v1>maxv)nxs6=nx6;
if (v1>maxv)maxv=v1;
}
}
}
}
}
}
if (px>50)maxv=-999;
goto1[s1][n1+1][n2+1][n3+1][n4+1][n5+1][n6+1][m+5]=nxs1;
goto2[s1][n1+1][n2+1][n3+1][n4+1][n5+1][n6+1][m+5]=nxs2;
goto3[s1][n1+1][n2+1][n3+1][n4+1][n5+1][n6+1][m+5]=nxs3;
goto4[s1][n1+1][n2+1][n3+1][n4+1][n5+1][n6+1][m+5]=nxs4;
goto5[s1][n1+1][n2+1][n3+1][n4+1][n5+1][n6+1][m+5]=nxs5;
goto6[s1][n1+1][n2+1][n3+1][n4+1][n5+1][n6+1][m+5]=nxs6;
gotom[s1][n1+1][n2+1][n3+1][n4+1][n5+1][n6+1][m+5]=mx;
v[s1][n1+1][n2+1][n3+1][n4+1][n5+1][n6+1][m+5]=maxv;
}
}
}
}
}
}
}
}
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++){
for (n6=-1;n6<2;n6++){
u1=u[10][n1+1][n2+1][n3+1][n4+1][n5+1][n6+1];
mx=-n1-n2-n4-n5+n3+n6;
px=0;
if (mx>5)px=100;
if (mx<-5)px=100;
if (px>50)mx=0;
nxs1=0;
nxs2=0;
nxs3=0;
nxs4=0;
nxs5=0;
nxs6=0;
maxv=-999;
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++){
for (nx6=-1;nx6<2;nx6++){
v1=u1+v[9][nx1+1][nx2+1][nx3+1][nx4+1][nx5+1][nx6+1][mx+5];
if (v1>maxv)nxs1=nx1;
if (v1>maxv)nxs2=nx2;
if (v1>maxv)nxs3=nx3;
if (v1>maxv)nxs4=nx4;
if (v1>maxv)nxs5=nx5;
if (v1>maxv)nxs6=nx6;
if (v1>maxv)maxv=v1;
}
}
}
}
}
}
if (px>50)maxv=-999;
end1[n1+1][n2+1][n3+1][n4+1][n5+1][n6+1]=nxs1;
end2[n1+1][n2+1][n3+1][n4+1][n5+1][n6+1]=nxs2;
end3[n1+1][n2+1][n3+1][n4+1][n5+1][n6+1]=nxs3;
end4[n1+1][n2+1][n3+1][n4+1][n5+1][n6+1]=nxs4;
end5[n1+1][n2+1][n3+1][n4+1][n5+1][n6+1]=nxs5;
end6[n1+1][n2+1][n3+1][n4+1][n5+1][n6+1]=nxs6;
endm[n1+1][n2+1][n3+1][n4+1][n5+1][n6+1]=mx;
endv[n1+1][n2+1][n3+1][n4+1][n5+1][n6+1]=maxv;
}
}
}
}
}
}
nx1=0;
nx2=0;
nx3=0;
nx4=0;
nx5=0;
nx6=0;
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++){
for (n6=-1;n6<2;n6++){
if (endv[n1+1][n2+1][n3+1][n4+1][n5+1][n6+1]>maxv)nx1=n1;
if (endv[n1+1][n2+1][n3+1][n4+1][n5+1][n6+1]>maxv)nx2=n2;
if (endv[n1+1][n2+1][n3+1][n4+1][n5+1][n6+1]>maxv)nx3=n3;
if (endv[n1+1][n2+1][n3+1][n4+1][n5+1][n6+1]>maxv)nx4=n4;
if (endv[n1+1][n2+1][n3+1][n4+1][n5+1][n6+1]>maxv)nx5=n5;
if (endv[n1+1][n2+1][n3+1][n4+1][n5+1][n6+1]>maxv)nx6=n6;
if (endv[n1+1][n2+1][n3+1][n4+1][n5+1][n6+1]>maxv)maxv=endv[n1+1][n2+1][n3+1][n4+1][n5+1][n6+1];
}
}
}
}
}
}
opc[10][1]=nx3;
op1[10][1]=nx1;
op2[10][1]=nx2;
opc[10][2]=nx6;
op1[10][2]=nx4;
op2[10][2]=nx5;
System.out.println(maxv);
m=endm[nx1+1][nx2+1][nx3+1][nx4+1][nx5+1][nx6+1];
for (j=1;j<10;j++){
s1=10-j;
n1=op1[s1+1][1];
n2=op2[s1+1][1];
n3=opc[s1+1][1];
n4=op1[s1+1][2];
n5=op2[s1+1][2];
n6=opc[s1+1][2];
op1[s1][1]=goto1[s1][n1+1][n2+1][n3+1][n4+1][n5+1][n6+1][m+5];
op2[s1][1]=goto2[s1][n1+1][n2+1][n3+1][n4+1][n5+1][n6+1][m+5];
opc[s1][1]=goto3[s1][n1+1][n2+1][n3+1][n4+1][n5+1][n6+1][m+5];
op1[s1][2]=goto4[s1][n1+1][n2+1][n3+1][n4+1][n5+1][n6+1][m+5];
op2[s1][2]=goto5[s1][n1+1][n2+1][n3+1][n4+1][n5+1][n6+1][m+5];
opc[s1][2]=goto6[s1][n1+1][n2+1][n3+1][n4+1][n5+1][n6+1][m+5];
m=gotom[s1][n1+1][n2+1][n3+1][n4+1][n5+1][n6+1][m+5];
}
e=0;
for (s1=2;s1<11;s1++){
for (s2=1;s2<3;s2++){
e=e+opc[s1][s2]*opc[s1][s2];
e=e+op1[s1][s2]*op1[s1][s2];
e=e+op2[s1][s2]*op2[s1][s2];
}
}
System.out.println(e);
t7=100;
if (maxv<-900)t1=1000;
if (maxv<-900)t7=0;
while(t7>50){
for (s1=2;s1<11;s1++){
for (s2=1;s2<3;s2++){
c[s1][s2]=c[s1][s2]+h*opc[s1][s2];
y1[s1][s2]=y1[s1][s2]+h*op1[s1][s2];
y2[s1][s2]=y2[s1][s2]+h*op2[s1][s2];
}
}
t7=0;
}
if (e<2)t1=1000;
t1=t1+1;
}
t2=t2+1;
}
for (s1=1;s1<11;s1++){
System.out.println(s1);
for (s2=1;s2<3;s2++){
System.out.println(c[s1][s2]);
System.out.println(y1[s1][s2]);
System.out.println(y2[s1][s2]);
}
}
}
static double trs(double tk,double tl,double[] th1,double[] th2){
double tr1,tr2,tr3,b1,b2;
int t1;
tr1=0.01;
tr2=0.4;
tr3=0;
b1=bud(tk,tl,tr1,th1,th2);
t1=0;
while(t1<100){
b2=bud(tk,tl,tr2,th1,th2);
tr3=tr2-b2*(tr2-tr1)/(b2-b1);
b1=b2;
tr1=tr2;
tr2=tr3;
b1=b2;
if (b2*b2<0.001)t1=1000;
t1=t1+1;
}
return tr3;
}
static double wel(double tk,double tl,double tr,double[] th1,double[] th2){
int s1,s2;
double ww,w1,w2,l1,l2,c1;
ww=0;
for (s1=1;s1<11;s1++){
for (s2=1;s2<3;s2++){
w1=(1-tk)*th1[s1];
w2=(1-tl)*th2[s2];
l1=mlx(s1,s2,tk,tl,tr,th1,th2);
l2=flx(s1,s2,tk,tl,tr,th1,th2);
c1=w1*l1+w2*l2+tr;
ww=ww+Math.log(c1)+Math.log(1-l1)+Math.log(1-l2);
}
}
return ww;
}
static double bud(double tk,double tl,double tr,double[] th1,double[] th2){
int s1,s2;
double b1,w1,w2,l1,l2,c1;
b1=0;
for (s1=1;s1<11;s1++){
for (s2=1;s2<3;s2++){
w1=(1-tk)*th1[s1];
w2=(1-tl)*th2[s2];
l1=mlx(s1,s2,tk,tl,tr,th1,th2);
l2=flx(s1,s2,tk,tl,tr,th1,th2);
c1=w1*l1+w2*l2+tr;
b1=b1+th1[s1]*l1+th2[s2]*l2-c1;
}
}
return b1;
}
static double mlx(int s1,int s2,double tk,double tl,double tr,double[] th1,double[] th2){
double uc,u1,u2,w1,w2,l1;
int px;
l1=0;
w1=(1-tk)*th1[s1];
w2=(1-tl)*th2[s2];
uc=1/tr;
u1=1/w1;
u2=1/w2;
px=0;
if (u1>uc)px=px+1;
if (u2>uc)px=px+1;
if (px==2)l1=0;
px=0;
if (u1>uc)px=px+1;
if (u2<uc)px=px+1;
if (px==2)l1=0;
px=0;
if (u1<uc)px=px+1;
if (u2>uc)px=px+1;
if (px==2)l1=(w1-tr)/2;
px=0;
if (u1<uc)px=px+1;
if (u2<uc)px=px+1;
if (px==2)l1=1-(w1+w2+tr)/(3*w1);
return l1;
}
static double flx(int s1,int s2,double tk,double tl,double tr,double[] th1,double[] th2){
double uc,u1,u2,w1,w2,l2;
int px;
l2=0;
w1=(1-tk)*th1[s1];
w2=(1-tl)*th2[s2];
uc=1/tr;
u1=1/w1;
u2=1/w2;
px=0;
if (u1>uc)px=px+1;
if (u2>uc)px=px+1;
if (px==2)l2=0;
px=0;
if (u1>uc)px=px+1;
if (u2<uc)px=px+1;
if (px==2)l2=(w2-tr)/2;
px=0;
if (u1<uc)px=px+1;
if (u2>uc)px=px+1;
if (px==2)l2=0;
px=0;
if (u1<uc)px=px+1;
if (u2<uc)px=px+1;
if (px==2)l2=1-(w1+w2+tr)/(3*w2);
return l2;
}
}
最終更新:2010年07月06日 00:31