プログラム倉庫

成功

#include <stdio.h>
#include <math.h>
double u(double c1,double l1,double l2){
double us,x1,x2,x3;
int pp;
x1=l1;
x2=l2;
x3=c1;
pp=0;
if (x1>0.99)pp=100;
if (x1<0)pp=100;
if (x2>0.99)pp=100;
if (x2<0)pp=100;
if (x3<0.01)pp=100;
if (pp>50)x1=0.5;
if (pp>50)x2=0.5;
if (pp>50)x3=0.5;
us=log(1-x1)+log(1-x2)+log(x3);
if (pp>50)us=-999;
return us;
}
double mlx(double w1,double w2,double tr){
double l1,l2,mls;
l1=1-(w1+w2+tr)/(3*w1);
l2=1-(w1+w2+tr)/(3*w2);
if (l1<0)  l2=(w2-tr)/(2*w2);
if (l1<0)  l1=0;
if (l2<0)  l1=(w1-tr)/(2*w1);
if (l2<0)  l2=0;
mls=l1;
return mls;
}

double flx(double w1,double w2,double tr){
double l1,l2,fls;
l1=1-(w1+w2+tr)/(3*w1);
l2=1-(w1+w2+tr)/(3*w2);
if (l1<0)  l2=(w2-tr)/(2*w2);
if (l1<0)  l1=0;
if (l2<0)  l1=(w1-tr)/(2*w1);
if (l2<0)  l2=0;
fls=l2;
return fls;
}



int main(void){
double th1[11],th2[11];
double w1,w2,tk,tl,tr,c1,l1,l2;
double tr1,tr2,tr3,b1,b2,wel;
int s1,s2,t,m1,m2,m3;
int n1,n2,n3,nx1,nx2,nx3;
double maxtk,maxtr,maxwel,maxtl,maxv;
double maxu,u1,u2,h,v1,vs,ww;
int max1,max2;
int check,q,qx,pp;
double y1[11][11],y2[11][11],c[11][11];
double z[11],ux[11][3][3][3],w[10][3][3][3],v[10][3][3][3][11],rw[11][3][3][3];
double end2[3][3][3],end1[3][3][3],endv[3][3][3];
double endq[3][3][3],endc[3][3][3];
double gotoc[10][3][3][3][11],goto1[10][3][3][3][11],goto2[10][3][3][3][11];
double gotoq[10][3][3][3][11];
int mx1,mx2,mx3,j,e,time;
double op1[11],op2[11],opc[11],opq[11];
for (s1=1;s1<=10;s1++){
th1[s1]=0.2*s1;
}
for (s2=1;s2<=10;s2++){
th2[s2]=0.1*s2;
}
maxwel=-999;
for (n1=10;n1<=40;n1++){
for (n2=10;n2<=40;n2++){
tk=0.01*n1;
tl=0.01*n2;
tr1=0.1;
tr2=0.05;
b1=0;
for (s1=1;s1<=10;s1++){
for (s2=1;s2<=10;s2++){
w1=(1-tk)*th1[s1];
w2=(1-tl)*th2[s2];
l1=mlx(w1,w2,tr1);
l2=flx(w1,w2,tr1);
c1=w1*l1+w2*l2+tr1;
b1=b1+th1[s1]*l1+th2[s2]*l2-c1;
}
}
t=0;
while (t<100){
b2=0;
for (s1=1;s1<=10;s1++){
for (s2=1;s2<=10;s2++){
w1=(1-tk)*th1[s1];
w2=(1-tl)*th2[s2];
l1=mlx(w1,w2,tr2);
l2=flx(w1,w2,tr2);
c1=w1*l1+w2*l2+tr2;
b2=b2+th1[s1]*l1+th2[s2]*l2-c1;
}
}
tr3=tr2-b2*(tr2-tr1)/(b2-b1);
tr1=tr2;
tr2=tr3;
b1=b2;
if (b2*b2<0.001)t=1000;
t=t+1;
}
tr=tr2;
wel=0;
for (s1=1;s1<=10;s1++){
for (s2=1;s2<=10;s2++){
w1=(1-tk)*th1[s1];
w2=(1-tl)*th2[s2];
l1=mlx(w1,w2,tr);
l2=flx(w1,w2,tr);
c1=w1*l1+w2*l2+tr;
wel=wel+log(c1)+log(1-l1)+log(1-l2);
}
}
if (wel>maxwel)maxtk=tk;
if (wel>maxwel)maxtl=tl;
if (wel>maxwel)maxtr=tr;
if (wel>maxwel)maxwel=wel;
}
}
tk=maxtk;
tl=maxtl;
tr=maxtr;
for (s1=1;s1<=10;s1++){
for (s2=1;s2<=10;s2++){
w1=(1-tk)*th1[s1];
w2=(1-tl)*th2[s2];
y1[s1][s2]=th1[s1]*mlx(w1,w2,tr);
y2[s1][s2]=th2[s2]*flx(w1,w2,tr);
c[s1][s2]=(1-tk)*y1[s1][s2]+(1-tl)*y2[s1][s2]+tr;
}
}
for (time=1;time<=5;time++){
for (s2=1;s2<=10;s2++){
h=0.001;
t=0;
while(t<100){
for (s1=1;s1<=10;s1++){
maxu=-999;
for (m1=1;m1<=10;m1++){
for (m2=1;m2<=10;m2++){
l1=(y1[m1][m2])/th1[s1];
l2=(y2[m1][m2])/th2[s2];
c1=c[m1][m2];
u1=u(c1,l1,l2);
if (s2==m2)u1=-999;
if (u1>maxu)maxu=u1;
}
}
z[s1]=maxu;
}
for (s1=1;s1<=10;s1++){
for (n1=-1;n1<=1;n1++){
for (n2=-1;n2<=1;n2++){
for (n3=-1;n3<=1;n3++){
l1=(y1[s1][s2]+n1*h)/th1[s1];
l2=(y2[s1][s2]+n2*h)/th2[s2];
c1=c[s1][s2]+n3*h;
u1=u(c1,l1,l2);
if (z[s1]>u1)u1=-999;
ux[s1][n1+1][n2+1][n3+1]=u1;
}
}
}
}
for (s1=1;s1<=10;s1++){
for (n1=-1;n1<=1;n1++){
for (n2=-1;n2<=1;n2++){
for (n3=-1;n3<=1;n3++){
check=0;
for (m1=1;m1<=10;m1++){
for (m2=1;m2<=10;m2++){
l1=y1[m1][m2]/th1[m1];
l2=y2[m1][m2]/th2[m2];
c1=c[m1][m2];
u1=u(c1,l1,l2);
l1=(y1[s1][s2]+n1*h)/th1[m1];
l2=(y2[s1][s2]+n2*h)/th2[m2];
c1=c[s1][s2]+n3*h;
u2=u(c1,l1,l2);
if (s2==m2)u2=-999;
if (u2>u1)check=100;
}
}
if(check>50)ux[s1][n1+1][n2+1][n3+1]=-999;
}
}
}
}
for (s1=1;s1<=9;s1++){
for (n1=-1;n1<=1;n1++){
for (n2=-1;n2<=1;n2++){
for (n3=-1;n3<=1;n3++){
l1=(y1[s1][s2]+n1*h)/th1[s1+1];
l2=(y2[s1][s2]+n2*h)/th2[s2];
c1=c[s1][s2]+n3*h;
w[s1][n1+1][n2+1][n3+1]=u(c1,l1,l2);
}
}
}
}
for (s1=2;s1<=10;s1++){
for (n1=-1;n1<=1;n1++){
for (n2=-1;n2<=1;n2++){
for (n3=-1;n3<=1;n3++){
l1=(y1[s1][s2]+n1*h)/th1[s1-1];
l2=(y2[s1][s2]+n2*h)/th2[s2];
c1=c[s1][s2]+n3*h;
rw[s1][n1+1][n2+1][n3+1]=u(c1,l1,l2);
}
}
}
}
for (n1=-1;n1<=1;n1++){
for (n2=-1;n2<=1;n2++){
for (n3=-1;n3<=1;n3++){
for (q=-5;q<=5;q++){
v[1][n1+1][n2+1][n3+1][q+5]=-999;
}
}
}
}
for (n1=-1;n1<=1;n1++){
for (n2=-1;n2<=1;n2++){
for (n3=-1;n3<=1;n3++){
q=n1+n2-n3;
v[1][n1+1][n2+1][n3+1][q+5]=ux[1][n1+1][n2+1][n3+1];
}
}
}
for (s1=2;s1<=9;s1++){
for (n1=-1;n1<=1;n1++){
for (n2=-1;n2<=1;n2++){
for (n3=-1;n3<=1;n3++){
for (q=-5;q<=5;q++){
u1=ux[s1][n1+1][n2+1][n3+1];
qx=q-n1-n2+n3;
pp=0;
if (qx>5)pp=100;
if (qx<-5)pp=100;
if (pp>10)qx=0;
maxv=-999;
for (m1=-1;m1<=1;m1++){
for (m2=-1;m2<=1;m2++){
for (m3=-1;m3<=1;m3++){
v1=u1+v[s1-1][m1+1][m2+1][m3+1][qx+5];
ww=w[s1-1][m1+1][m2+1][m3+1];
if (ww>u1)v1=-999;
if (rw[s1][n1+1][n2+1][n3+1]>ux[s1-1][m1+1][m2+1][m3+1])v1=-999;
if (v1>maxv)mx1=m1;
if (v1>maxv)mx2=m2;
if (v1>maxv)mx3=m3;
if (v1>maxv)maxv=v1;
}
}
}
if (pp>10)maxv=-999;
v[s1][n1+1][n2+1][n3+1][q+5]=maxv;
gotoc[s1][n1+1][n2+1][n3+1][q+5]=mx3;
goto1[s1][n1+1][n2+1][n3+1][q+5]=mx1;
goto2[s1][n1+1][n2+1][n3+1][q+5]=mx2;
gotoq[s1][n1+1][n2+1][n3+1][q+5]=qx;
}
}
}
}
}
for (n1=-1;n1<=1;n1++){
for (n2=-1;n2<=1;n2++){
for (n3=-1;n3<=1;n3++){
u1=ux[10][n1+1][n2+1][n3+1];
qx=n3-n1-n2;
maxv=-999;
for (m1=-1;m1<=1;m1++){
for (m2=-1;m2<=1;m2++){
for (m3=-1;m3<=1;m3++){
v1=u1+v[9][m1+1][m2+1][m3+1][qx+5];
ww=w[9][m1+1][m2+1][m3+1];
if (ww>u1)v1=-999;
if (rw[10][n1+1][n2+1][n3+1]>ux[9][m1+1][m2+1][m3+1])v1=-999;
if (v1>maxv)mx1=m1;
if (v1>maxv)mx2=m2;
if (v1>maxv)mx3=m3;
if (v1>maxv)maxv=v1;
}
}
}
endv[n1+1][n2+1][n3+1]=maxv;
endc[n1+1][n2+1][n3+1]=mx3;
end1[n1+1][n2+1][n3+1]=mx1;
end2[n1+1][n2+1][n3+1]=mx2;
endq[n1+1][n2+1][n3+1]=qx;
}
}
}
maxv=-999;
for (n1=-1;n1<=1;n1++){
for (n2=-1;n2<=1;n2++){
for (n3=-1;n3<=1;n3++){
if (endv[n1+1][n2+1][n3+1]>maxv)nx1=n1;
if (endv[n1+1][n2+1][n3+1]>maxv)nx2=n2;
if (endv[n1+1][n2+1][n3+1]>maxv)nx3=n3;
if (endv[n1+1][n2+1][n3+1]>maxv)maxv=endv[n1+1][n2+1][n3+1];
}
}
}
opc[10]=nx3;
op1[10]=nx1;
op2[10]=nx2;
opc[9]=endc[nx1+1][nx2+1][nx3+1];
op1[9]=end1[nx1+1][nx2+1][nx3+1];
op2[9]=end2[nx1+1][nx2+1][nx3+1];
opq[9]=endq[nx1+1][nx2+1][nx3+1];
for (j=1;j<=8;j++){
s1=9-j;
n1=op1[s1+1];
n2=op2[s1+1];
n3=opc[s1+1];
q=opq[s1+1];
opc[s1]=gotoc[s1+1][n1+1][n2+1][n3+1][q+5];
op1[s1]=goto1[s1+1][n1+1][n2+1][n3+1][q+5];
op2[s1]=goto2[s1+1][n1+1][n2+1][n3+1][q+5];
opq[s1]=gotoq[s1+1][n1+1][n2+1][n3+1][q+5];
}
e=0;
for (s1=1;s1<=10;s1++){
e=e+opc[s1]*opc[s1]+op1[s1]*op1[s1]+op2[s1]*op2[s1];
}
for (s1=1;s1<=10;s1++){
c[s1][s2]=c[s1][s2]+opc[s1]*h;
y1[s1][s2]=y1[s1][s2]+op1[s1]*h;
y2[s1][s2]=y2[s1][s2]+op2[s1]*h;
}

if (e<1)h=h/2;
if (h<0.00001)t=1000;
t=t+1;
}
printf("%f",maxv);
printf("\n");
}
for (s1=1;s1<=10;s1++){
h=0.001;
t=0;
while(t<100){
for (s2=1;s2<=10;s2++){
maxu=-999;
for (m1=1;m1<=10;m1++){
for (m2=1;m2<=10;m2++){
l1=(y1[m1][m2])/th1[s1];
l2=(y2[m1][m2])/th2[s2];
c1=c[m1][m2];
u1=u(c1,l1,l2);
if (s1==m1)u1=-999;
if (u1>maxu)maxu=u1;
}
}
z[s2]=maxu;
}
for (s2=1;s2<=10;s2++){
for (n1=-1;n1<=1;n1++){
for (n2=-1;n2<=1;n2++){
for (n3=-1;n3<=1;n3++){
l1=(y1[s1][s2]+n1*h)/th1[s1];
l2=(y2[s1][s2]+n2*h)/th2[s2];
c1=c[s1][s2]+n3*h;
u1=u(c1,l1,l2);
if (z[s2]>u1)u1=-999;
ux[s2][n1+1][n2+1][n3+1]=u1;
}
}
}
}
for (s2=1;s2<=10;s2++){
for (n1=-1;n1<=1;n1++){
for (n2=-1;n2<=1;n2++){
for (n3=-1;n3<=1;n3++){
check=0;
for (m1=1;m1<=10;m1++){
for (m2=1;m2<=10;m2++){
l1=y1[m1][m2]/th1[m1];
l2=y2[m1][m2]/th2[m2];
c1=c[m1][m2];
u1=u(c1,l1,l2);
l1=(y1[s1][s2]+n1*h)/th1[m1];
l2=(y2[s1][s2]+n2*h)/th2[m2];
c1=c[s1][s2]+n3*h;
u2=u(c1,l1,l2);
if (s1==m1)u2=-999;
if (u2>u1)check=100;
}
}
if(check>50)ux[s2][n1+1][n2+1][n3+1]=-999;
}
}
}
}

for (s2=1;s2<=9;s2++){
for (n1=-1;n1<=1;n1++){
for (n2=-1;n2<=1;n2++){
for (n3=-1;n3<=1;n3++){
l1=(y1[s1][s2]+n1*h)/th1[s1];
l2=(y2[s1][s2]+n2*h)/th2[s2+1];
c1=c[s1][s2]+n3*h;
w[s2][n1+1][n2+1][n3+1]=u(c1,l1,l2);
}
}
}
}
for (s2=2;s2<=10;s2++){
for (n1=-1;n1<=1;n1++){
for (n2=-1;n2<=1;n2++){
for (n3=-1;n3<=1;n3++){
l1=(y1[s1][s2]+n1*h)/th1[s1];
l2=(y2[s1][s2]+n2*h)/th2[s2-1];
c1=c[s1][s2]+n3*h;
rw[s2][n1+1][n2+1][n3+1]=u(c1,l1,l2);
}
}
}
}

for (n1=-1;n1<=1;n1++){
for (n2=-1;n2<=1;n2++){
for (n3=-1;n3<=1;n3++){
for (q=-5;q<=5;q++){
v[1][n1+1][n2+1][n3+1][q+5]=-999;
}
}
}
}
for (n1=-1;n1<=1;n1++){
for (n2=-1;n2<=1;n2++){
for (n3=-1;n3<=1;n3++){
q=n1+n2-n3;
v[1][n1+1][n2+1][n3+1][q+5]=ux[1][n1+1][n2+1][n3+1];
}
}
}
for (s2=2;s2<=9;s2++){
for (n1=-1;n1<=1;n1++){
for (n2=-1;n2<=1;n2++){
for (n3=-1;n3<=1;n3++){
for (q=-5;q<=5;q++){
u1=ux[s2][n1+1][n2+1][n3+1];
qx=q-n1-n2+n3;
pp=0;
if (qx>5)pp=100;
if (qx<-5)pp=100;
if (pp>10)qx=0;
maxv=-999;
for (m1=-1;m1<=1;m1++){
for (m2=-1;m2<=1;m2++){
for (m3=-1;m3<=1;m3++){
v1=u1+v[s2-1][m1+1][m2+1][m3+1][qx+5];
ww=w[s2-1][m1+1][m2+1][m3+1];
if (ww>u1)v1=-999;
if (rw[s2][n1+1][n2+1][n3+1]>ux[s2-1][m1+1][m2+1][m3+1])v1=-999;
if (v1>maxv)mx1=m1;
if (v1>maxv)mx2=m2;
if (v1>maxv)mx3=m3;
if (v1>maxv)maxv=v1;
}
}
}
if (pp>10)maxv=-999;
v[s2][n1+1][n2+1][n3+1][q+5]=maxv;
gotoc[s2][n1+1][n2+1][n3+1][q+5]=mx3;
goto1[s2][n1+1][n2+1][n3+1][q+5]=mx1;
goto2[s2][n1+1][n2+1][n3+1][q+5]=mx2;
gotoq[s2][n1+1][n2+1][n3+1][q+5]=qx;
}
}
}
}
}
for (n1=-1;n1<=1;n1++){
for (n2=-1;n2<=1;n2++){
for (n3=-1;n3<=1;n3++){
u1=ux[10][n1+1][n2+1][n3+1];
qx=n3-n1-n2;
maxv=-999;
for (m1=-1;m1<=1;m1++){
for (m2=-1;m2<=1;m2++){
for (m3=-1;m3<=1;m3++){
v1=u1+v[9][m1+1][m2+1][m3+1][qx+5];
ww=w[9][m1+1][m2+1][m3+1];
if (ww>u1)v1=-999;
if (rw[10][n1+1][n2+1][n3+1]>ux[9][m1+1][m2+1][m3+1])v1=-999;
if (v1>maxv)mx1=m1;
if (v1>maxv)mx2=m2;
if (v1>maxv)mx3=m3;
if (v1>maxv)maxv=v1;
}
}
}
endv[n1+1][n2+1][n3+1]=maxv;
endc[n1+1][n2+1][n3+1]=mx3;
end1[n1+1][n2+1][n3+1]=mx1;
end2[n1+1][n2+1][n3+1]=mx2;
endq[n1+1][n2+1][n3+1]=qx;
}
}
}
maxv=-999;
for (n1=-1;n1<=1;n1++){
for (n2=-1;n2<=1;n2++){
for (n3=-1;n3<=1;n3++){
if (endv[n1+1][n2+1][n3+1]>maxv)nx1=n1;
if (endv[n1+1][n2+1][n3+1]>maxv)nx2=n2;
if (endv[n1+1][n2+1][n3+1]>maxv)nx3=n3;
if (endv[n1+1][n2+1][n3+1]>maxv)maxv=endv[n1+1][n2+1][n3+1];
}
}
}
opc[10]=nx3;
op1[10]=nx1;
op2[10]=nx2;
opc[9]=endc[nx1+1][nx2+1][nx3+1];
op1[9]=end1[nx1+1][nx2+1][nx3+1];
op2[9]=end2[nx1+1][nx2+1][nx3+1];
opq[9]=endq[nx1+1][nx2+1][nx3+1];
for (j=1;j<=8;j++){
s2=9-j;
n1=op1[s2+1];
n2=op2[s2+1];
n3=opc[s2+1];
q=opq[s2+1];
opc[s2]=gotoc[s2+1][n1+1][n2+1][n3+1][q+5];
op1[s2]=goto1[s2+1][n1+1][n2+1][n3+1][q+5];
op2[s2]=goto2[s2+1][n1+1][n2+1][n3+1][q+5];
opq[s2]=gotoq[s2+1][n1+1][n2+1][n3+1][q+5];
}

e=0;
for (s2=1;s2<=10;s2++){
e=e+opc[s2]*opc[s2]+op1[s2]*op1[s2]+op2[s2]*op2[s2];
}
for (s2=1;s2<=10;s2++){
c[s1][s2]=c[s1][s2]+opc[s2]*h;
y1[s1][s2]=y1[s1][s2]+op1[s2]*h;
y2[s1][s2]=y2[s1][s2]+op2[s2]*h;
}
if (e<1)h=h/2;
if (h<0.00001)t=1000;
t=t+1;
}
printf("%f",maxv);
printf("\n");
}
}
for (s1=1;s1<=10;s1++){
for (s2=1;s2<=10;s2++){
printf("%f",c[s1][s2]);
printf(",");
printf("%f",y1[s1][s2]);
printf(",");
printf("%f",y2[s1][s2]);
printf("\n");
}
}
return 0;
}