アットウィキロゴ

p100

class pro{
public static void main(String args[]){
int s;
double th[]=new double[101];
double c[]=new double[101];
double y[]=new double[101];
double u[][][]=new double[101][3][3];
double v[][][]=new double[101][3][3];
int goto1[][][]=new int[101][3][3];
int goto2[][][]=new int[101][3][3];
int opc[]=new int[101];
int opy[]=new int[101];
double lam;
int n1,n2,nx1,nx2,nxs1,nxs2;
double c1,y1,v1,maxv,u1;
double h;
int j,e;
int t1,t2;
for (s=1;s<101;s++){
th[s]=1+0.01*s;
}

for (s=1;s<101;s++){
y[s]=0.5*th[s];
c[s]=y[s];
}

lam=1.2;
h=0.02;
t2=0;
while(t2<5){
h=h/2;
t1=0;
while(t1<100){
for (s=1;s<101;s++){
for (n1=-1;n1<2;n1++){
for (n2=-1;n2<2;n2++){
c1=c[s]+n1*h;
y1=y[s]+n2*h;
u[s][n1+1][n2+1]=Math.log(c1)+Math.log(1-y1/th[s])+lam*(y1-c1);
}
}
}


for (n1=-1;n1<2;n1++){
for (n2=-1;n2<2;n2++){
v[1][n1+1][n2+1]=u[1][n1+1][n2+1];
}
}

for (s=2;s<101;s++){
for (n1=-1;n1<2;n1++){
for (n2=-1;n2<2;n2++){
u1=u[s][n1+1][n2+1];
maxv=-999;
nxs1=0;
nxs2=0;
for (nx1=-1;nx1<2;nx1++){
for (nx2=-1;nx2<2;nx2++){
v1=u1+v[s-1][nx1+1][nx2+1];
if (v1>maxv)nxs1=nx1;
if (v1>maxv)nxs2=nx2;
if (v1>maxv)maxv=v1;
}
}
goto1[s][n1+1][n2+1]=nxs1;
goto2[s][n1+1][n2+1]=nxs2;
v[s][n1+1][n2+1]=maxv;
}
}
}

nx1=0;
nx2=0;
maxv=-999;
for (n1=-1;n1<2;n1++){
for (n2=-1;n2<2;n2++){
if (v[100][n1+1][n2+1]>maxv)nx1=n1;
if (v[100][n1+1][n2+1]>maxv)nx2=n2;
if (v[100][n1+1][n2+1]>maxv)maxv=v[100][n1+1][n2+1];
}
}

opc[100]=nx1;
opy[100]=nx2;
for (j=1;j<100;j++){
s=100-j;
n1=opc[s+1];
n2=opy[s+1];
opc[s]=goto1[s+1][n1+1][n2+1];
opy[s]=goto2[s+1][n1+1][n2+1];
}
System.out.println(maxv);
for (s=1;s<101;s++){
c[s]=c[s]+opc[s]*h;
y[s]=y[s]+opy[s]*h;
}

e=0;
for (s=1;s<101;s++){
e=e+opc[s]*opc[s];
e=e+opy[s]*opy[s];
}
if (e<2)t1=1000;
System.out.println(e);
t1=t1+1;
}
t2=t2+1;
}

for (s=1;s<101;s++){
System.out.println(c[s]);
}

for (s=1;s<101;s++){
System.out.println(y[s]);

}


}
}
最終更新:2010年07月02日 23:03