class pro{
public static void main(String args[]){
int s;
int n1,n2;
double th[]=new double[101];
double p[]=new double[101];
double q[]=new double[101];
double rev[][][]=new double[101][3][3];
double u[][][]=new double[101][3][3];
double w[][][]=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];
double beta;
double pp,x,c;
double u1,v1,w1;
double r,h,r1;
double maxrev,maxv;
double p1,q1;
int nx1,nx2,mxs1,nxs2;
beta=1;
nx1=0;
nx2=0;
maxrev=0;
for (n1=1;n1<50;n1++){
for (n2=1;n2<11;n2++){
pp=n1;
c=n2;
for (s=1;s<101;s++){
th[s]=s;
}
r=0;
for (s=1;s<101;s++){
x=(th[s]-pp)/(2*beta);
if (x<0)x=0;
u1=th[s]*x*x-beta*x-pp*x-c;
if (u1<0)x=0;
r=r+pp*x+c;
}
if (r>maxrev)nx1=n1;
if (r>maxrev)nx2=n2;
if (r>maxrev)maxrev=r;
}
}
System.out.println(maxrev);
System.out.println(nx1);
System.out.println(nx2);
pp=nx1;
c=nx2;
for (s=1;s<101;s++){
x=(th[s]-pp)/(2*beta);
if (x<0)x=0;
u1=th[s]*x*x-beta*x-pp*x-c;
if (u1<0)x=0;
q[s]=x;
p[s]=pp*q[s]+c;
}
h=0.01;
for (s=1;s<101;s++){
for (n1=-1;n1<2;n1++){
for (n2=-1;n2<2;n2++){
p1=p[s]+n1*h;
q1=q[s]+n2*h;
rev[s][n1+1][n2+1]=p1;
}
}
}
for (s=1;s<101;s++){
for (n1=-1;n1<2;n1++){
for (n2=-1;n2<2;n2++){
p1=p[s]+n1*h;
q1=q[s]+n2*h;
u[s][n1+1][n2+1]=th[s]*q1-beta*q1-p1;
}
}
}
for (s=1;s<100;s++){
for (n1=-1;n1<2;n1++){
for (n2=-1;n2<2;n2++){
p1=p[s]+n1*h;
q1=q[s]+n2*h;
w[s][n1+1][n2+1]=th[s+1]*q1-beta*q1-p1;
}
}
}
for (n1=-1;n1<2;n1++){
for (n2=-1;n2<2;n2++){
v[1][n1+1][n2+1]=rev[1][n1+1][n2+1];
}
}
for (s=2;s<101;s++){
for (n1=-1;n1<2;n1++){
for (n2=-1;n2<2;n2++){
r1=rev[s][n1+1][n2+1];
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=r1+v[s-1][nx1+1][nx2+1];
w1=u[s-1][nx1+1][nx2+1];
if (w1>u1)v1=-999;
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;
}
}
}
maxv=-999;
for (n1=-1;n1<2;n1++){
for (n2=-1;n2<2;n2++){
if (v[100][n1+1][n2+1]>maxv)maxv=v[100][n1+1][n2+1];
}
}
System.out.println(maxv);
}
}
最終更新:2010年07月12日 09:01