package h2;
public class pro {
int[] y=new int[200];
int[] p=new int[200];
double[][][] v=new double[200][21][21];
int[][][] goton=new int[200][21][21];
int[][][] gotom=new int[200][21][21];
int s;
double phi;
int[] opn=new int[200];
int[] opm=new int[200];
public static void main(String[] args) {
pro test=new pro();
}
pro(){
phi=0.5;
y[0]=100;
p[0]=100;
for(s=1;s<102;s++){
y[s]=100;
p[s]=100;
}
double theta,lam,beta;
theta=0.5;
lam=0.5;
beta=0.5;
int n,m;
int gap,yy;
int gg;
gg=0;
int t=1;
for(n=1;n<21;n++){
for(m=1;m<21;m++){
v[1][m][n]=0;
}}
int nx,mx,nxs,mxs;
int g;
for(t=2;t<101;t++){
for(n=1;n<21;n++){
for(m=1;m<21;m++){
gap=n-10;
g=m-10;
yy=y[t]-gap;
double maxv=9999;
nxs=0;
mxs=0;
for(nx=1;nx<21;nx++){
for(mx=1;mx<21;mx++){
int gap2=nx-10;
int yy2=y[t-1]-gap2;
double e1=gap-phi*gap2;
double e2=yy-yy2-g;
int g2=mx-10;
double e3=g-theta*gg-(1-theta)*g2;
double e4=p[t]-(1-lam)*p[t+1]-lam*p[t-1]-beta*gap;
double v1=e1*e1+e2*2+e3*e3+e4*e4+v[t-1][mx][nx];
if(v1<maxv)nxs=nx;
if(v1<maxv)mxs=mx;
if(v1<maxv)maxv=v1;
}}
goton[t][m][n]=nxs;
gotom[t][m][n]=mxs;
v[t][m][n]=maxv;
}}}
double maxv=9999;
mx=0;
nx=0;
for(n=1;n<21;n++){
for(m=1;m<21;m++){
if(v[100][m][n]<maxv)mx=m;
if(v[100][m][n]<maxv)nx=n;
if(v[100][m][n]<maxv)maxv=v[100][m][n];
}}
opn[100]=nx;
opm[100]=mx;
for(s=1;s<100;s++){
t=101-s;
m=opm[t];
n=opn[t];
opm[t-1]=gotom[t][m][n];
opn[t-1]=goton[t][m][n];
}
for(s=1;s<101;s++){
System.out.println(y[s]+","+(opn[s]-10));
}
}
}
最終更新:2015年04月20日 23:24