class sample{
public static void main(String args[]){
double th[]= new double[101];
double c[]= new double[101];
double y[]= new double[101];
int opc[]= new int[101];
int opy[]= new int[101];
int opq[]= new int[101];
double u[][][]=new double[101][3][3];
double ww[][][]=new double[100][3][3];
double v[][][][]=new double[100][3][3][21];
int gotoc[][][][]=new int[100][3][3][21];
int gotoy[][][][]=new int[100][3][3][21];
int gotoq[][][][]=new int[100][3][3][21];
double endv[][]=new double[3][3];
int endc[][]=new int[3][3];
int endy[][]=new int[3][3];
int endq[][]=new int[3][3];
int s;
double tl;
double tr;
double ls;
double w;
double cs;
double ys;
double b1;
double b2;
double tr1;
double tr2;
double tr3;
double wel;
double maxwel;
double maxtl;
double maxtr;
int t;
int n;
int n1;
int n2;
int pp;
int q;
int j;
double c1;
double l1;
double h;
double u1;
int ns1;
int ns2;
int qx;
int nx1;
int nx2;
double vs;
double v1;
double maxv;
double dc;
double dy;
int e;
for (s=1;s<101;s++){
th[s]=0.02*s;
}
maxtl=0;
maxwel=-999;
maxtr=0;
for (n=20;n<45;n++){
tl=0.01*n;
tr1=0.01;
tr2=0.02;
tr=tr1;
b1=0;
for (s=1;s<101;s++){
w=(1-tl)*th[s];
ls=(w-tr)/(2*w);
if (ls<0){
ls=0;
}
ys=th[s]*ls;
cs=w*ls+tr;
b1=b1+ys-cs;
}
t=0;
while (t<100) {
tr=tr2;
b2=0;
for (s=1;s<101;s++){
w=(1-tl)*th[s];
ls=(w-tr)/(2*w);
if (ls<0){
ls=0;
}
ys=th[s]*ls;
cs=w*ls+tr;
b2=b2+ys-cs;
}
tr3=tr2-b2*(tr2-tr1)/(b2-b1);
tr1=tr2;
tr2=tr3;
b1=b2;
if (b2*b2<0.00001){
t=1000;
}
t=t+1;
}
tr=tr2;
wel=0;
for (s=1;s<101;s++){
w=(1-tl)*th[s];
ls=(w-tr)/(2*w);
if (ls<0){
ls=0;
}
cs=w*ls+tr;
wel=wel+Math.log(cs)+Math.log(1-ls);
}
if (wel>maxwel){
maxtl=tl;
}
if (wel>maxwel){
maxtr=tr;
}
if (wel>maxwel){
maxwel=wel;
}
}
tl=maxtl;
tr=maxtr;
for (s=1;s<101;s++){
w=(1-tl)*th[s];
ls=(w-tr)/(2*w);
if (ls<0){
ls=0;
}
c[s]=w*ls+tr;
y[s]=th[s]*ls;
}
h=0.001;
t=0;
while(t<1000){
for (s=1;s<101;s++){
for (n1=-1;n1<2;n1++){
for (n2=-1;n2<2;n2++){
c1=c[s]+n1*h;
l1=(y[s]+n2*h)/th[s];
pp=0;
if (l1<0){
pp=100;
}
if (pp>50){
l1=0.5;
}
u1=Math.log(c1)+Math.log(1-l1);
if (pp>50){
u1=-999;
}
u[s][n1+1][n2+1]=u1;
}
}
}
for (s=1;s<100;s++){
for (n1=-1;n1<2;n1++){
for (n2=-1;n2<2;n2++){
c1=c[s]+n1*h;
l1=(y[s]+n2*h)/th[s+1];
pp=0;
if (l1<0){
pp=100;
}
if (pp>50){
l1=0.5;
}
u1=Math.log(c1)+Math.log(1-l1);
if (pp>50){
u1=-999;
}
ww[s][n1+1][n2+1]=u1;
}
}
}
for (n1=-1;n1<2;n1++){
for (n2=-1;n2<2;n2++){
for (q=-10;q<11;q++){
v[1][n1+1][n2+1][q+10]=-999;
}
}
}
for (n1=-1;n1<2;n1++){
for (n2=-1;n2<2;n2++){
q=n2-n1;
v[1][n1+1][n2+1][q+10]=u[1][n1+1][n2+1];
}
}
for (s=2;s<100;s++){
for (n1=-1;n1<2;n1++){
for (n2=-1;n2<2;n2++){
for (q=-10;q<11;q++){
u1=u[s][n1+1][n2+1];
qx=q-n1+n2;
pp=0;
if (qx>10){
pp=100;
}
if (qx<-10){
pp=100;
}
if (pp>50){
qx=0;
}
vs=-999;
ns1=0;
ns2=0;
for (nx1=-1;nx1<2;nx1++){
for (nx2=-1;nx2<2;nx2++){
v1=u1+v[s-1][nx1+1][nx2+1][qx+10];
if (ww[s-1][nx1+1][nx2+1]>u1){
v1=-999;
}
if (v1>vs){
ns1=nx1;
}
if (v1>vs){
ns2=nx2;
}
if (v1>vs){
vs=v1;
}
}
}
if (pp>50){
vs=-999;
}
gotoc[s][n1+1][n2+1][q+10]=ns1;
gotoy[s][n1+1][n2+1][q+10]=ns2;
gotoq[s][n1+1][n2+1][q+10]=qx;
v[s][n1+1][n2+1][q+10]=vs;
}
}
}
}
for (n1=-1;n1<2;n1++){
for (n2=-1;n2<2;n2++){
u1=u[100][n1+1][n2+1];
qx=n2-n1;
vs=-999;
ns1=0;
ns2=0;
for (nx1=-1;nx1<2;nx1++){
for (nx2=-1;nx2<2;nx2++){
v1=u1+v[99][nx1+1][nx2+1][qx+10];
if (ww[99][nx1+1][nx2+1]>u1){
v1=-999;
}
if (v1>vs){
ns1=nx1;
}
if (v1>vs){
ns2=nx2;
}
if (v1>vs){
vs=v1;
}
}
}
endc[n1+1][n2+1]=ns1;
endy[n1+1][n2+1]=ns2;
endq[n1+1][n2+1]=qx;
endv[n1+1][n2+1]=vs;
}
}
maxv=-999;
ns1=0;
ns2=0;
for (n1=-1;n1<2;n1++){
for (n2=-1;n2<2;n2++){
if (endv[n1+1][n2+1]>maxv){
ns1=n1;
}
if (endv[n1+1][n2+1]>maxv){
ns2=n2;
}
if (endv[n1+1][n2+1]>maxv){
maxv=endv[n1+1][n2+1];
}
}
}
opc[100]=ns1;
opy[100]=ns2;
opc[99]=endc[opc[100]+1][opy[100]+1];
opy[99]=endy[opc[100]+1][opy[100]+1];
opq[99]=endq[opc[100]+1][opy[100]+1];
for (j=1;j<99;j++){
s=99-j;
opc[s]=gotoc[s+1][opc[s+1]+1][opy[s+1]+1][opq[s+1]+10];
opy[s]=gotoy[s+1][opc[s+1]+1][opy[s+1]+1][opq[s+1]+10];
opq[s]=gotoq[s+1][opc[s+1]+1][opy[s+1]+1][opq[s+1]+10];
}
e=0;
for (s=1;s<101;s++){
e=e+opc[s]*opc[s]+opy[s]*opy[s];
}
for (s=1;s<101;s++){
c[s]=c[s]+opc[s]*h;
y[s]=y[s]+opy[s]*h;
}
System.out.println(maxv);
if (e<2){
h=h/2;
}
if (h<0.00001){
t=10000;
}
t=t+1;
}
for (s=1;s<100;s++){
dy=y[s+1]-y[s];
dc=c[s+1]-c[s];
if (dy>0){
System.out.println(1-dc/dy);
}
}
}
}
最終更新:2009年12月07日 17:24