package w;
public class pro {
int s,e;
int th[]= new int[101];
int c[]= new int[101];
int y[]= new int[101];
double h;
public static void main(String[] args) {
pro test=new pro();
}
pro(){
h=0.01;
for (s=1;s<101;s++){
th[s]=10*s;
}
nearlinear sub=new nearlinear();
sub.th=th;
sub.h=h;
sub.makedata();
c=sub.c;
y=sub.y;
int time;
time=0;
for(time=1;time<20;time++){
nonlinear sub2=new nonlinear();
sub2.th=th;
sub2.h=h;
sub2.c=c;
sub2.y=y;
sub2.makedata();
c=sub2.c;
y=sub2.y;
}
for(s=1;s<101;s++){
System.out.println(c[s]+","+y[s]);
}
}
}
package w;
class nonlinear{
int[] th= new int[101];
int[] c= new int[101];
int[] y= new int[101];
int[] opw= new int[101];
int[] opb= new int[101];
int[][][] opc= new int[101][11][11];
int[][][] opy= new int[101][11][11];
double h;
double z;
double[][][] ux= new double[101][11][11];
double[][][] wx= new double[101][11][11];
double[][][] v= new double[101][11][101];
int[][][] gotow= new int[101][11][101];
int[][][] gotob= new int[101][11][101];
int[][][] nearu= new int[101][11][11];
int[][][] nearw= new int[101][11][11];
double[][][] chu= new double[101][11][11];
int[] ws= new int[101];
int s,n1,n2,m1,m2,mx;
double c1,l1,u1;
double maxu;
void makedata(){
for (s=1;s<101;s++){
for (n1=-5;n1<6;n1++){
for (n2=-5;n2<6;n2++){
c1=(c[s]+n1)*h;
l1=(double)(y[s]+n2)/th[s];
u1=u(c1,1-l1);
ux[s][n1+5][n2+5]=u1;
}
}
}
for (s=1;s<100;s++){
for (n1=-5;n1<6;n1++){
for (n2=-5;n2<6;n2++){
c1=(c[s]+n1)*h;
l1=(double)(y[s]+n2)/th[s+1];
u1=u(c1,1-l1);
wx[s][n1+5][n2+5]=u1;
}
}
}
for (s=1;s<101;s++){
for (n1=-5;n1<6;n1++){
for (n2=-5;n2<6;n2++){
nearu[s][n1+5][n2+5]=search(ux[s][n1+5][n2+5]);
}
}
}
for (s=1;s<100;s++){
for (n1=-5;n1<6;n1++){
for (n2=-5;n2<6;n2++){
nearw[s][n1+5][n2+5]=search(wx[s][n1+5][n2+5]);
}
}
}
for (s=1;s<100;s++){
ws[s]=nearw[s][5][5];
}
int x1,x2;
for (s=1;s<100;s++){
for (m1=-5;m1<6;m1++){
for (m2=-5;m2<6;m2++){
maxu=-999;
x1=0;
x2=0;
for (n2=-5;n2<6;n2++){
n1=n2-m2;
z=0;
if(n1>5)z=100;
if(n1<-5)z=100;
if(z>50)n1=0;
u1=ux[s][n1+5][n2+5];
mx=nearw[s][n1+5][n2+5];
if(mx>m1+ws[s])z=100;
if(z>50)u1=-999;
if(u1>maxu)x1=n1;
if(u1>maxu)x2=n2;
if(u1>maxu)maxu=u1;
}
chu[s][m1+5][m2+5]=maxu;
opc[s][m1+5][m2+5]=x1+c[s];
opy[s][m1+5][m2+5]=x2+y[s];
}
}
}
for (m1=-5;m1<6;m1++){
for (m2=-50;m2<51;m2++){
v[1][m1+5][m2+50]=-999;
}
}
for (m1=-5;m1<6;m1++){
for (m2=-5;m2<6;m2++){
v[1][m1+5][m2+50]=chu[1][m1+5][m2+5];
}
}
int bx,bxs,p1,bps,ps;
double v1,maxv;
for (s=2;s<100;s++){
for (m1=-5;m1<6;m1++){
for (m2=-50;m2<51;m2++){
maxv=-999;
ps=0;
bps=0;
for(bx=-5;bx<5;bx++){
u1=chu[s][m1+5][bx+5];
p1=search(u1)-ws[s-1];
bxs=m2-bx;
z=0;
if(bxs>50)z=100;
if(bxs<-50)z=100;
if(p1>5)z=100;
if(p1<-5)z=100;
if(z>50)bxs=0;
if(z>50)p1=0;
v1=u1+v[s-1][p1+5][bxs+50];
if(z>50)v1=-999;
if(v1>maxv)bps=bxs;
if(v1>maxv)ps=p1;
if(v1>maxv)maxv=v1;
}
v[s][m1+5][m2+50]=maxv;
gotob[s][m1+5][m2+50]=bps;
gotow[s][m1+5][m2+50]=ps;
}
}
}
int nx1,nx2,px;
s=100;
maxv=-999;
nx1=0;
nx2=0;
bxs=0;
px=0;
for (n1=-5;n1<6;n1++){
for (n2=-5;n2<6;n2++){
u1=ux[s][n1+5][n2+5];
p1=nearu[s][n1+5][n2+5]-ws[s-1];
bx=n1-n2;
z=0;
if(p1<-5)z=100;
if(p1>5)z=100;
if(z>50)p1=0;
v1=u1+v[s-1][p1+5][bx+50];
if(z>50)v1=-999;
if(v1>maxv)nx1=n1;
if(v1>maxv)nx2=n2;
if(v1>maxv)px=p1;
if(v1>maxv)bxs=bx;
if(v1>maxv)maxv=v1;
}
}
opb[99]=bxs;
opw[99]=px;
int j;
for(j=1;j<99;j++){
s=100-j;
bx=opb[s];
px=opw[s];
opb[s-1]=gotob[s][px+5][bx+50];
opw[s-1]=gotow[s][px+5][bx+50];
}
s=1;
bx=opb[s];
px=opw[s];
c[s]=opc[s][px+5][bx+5];
y[s]=opy[s][px+5][bx+5];
for(s=2;s<100;s++){
bx=opb[s]-opb[s-1];
px=opw[s];
c[s]=opc[s][px+5][bx+5];
y[s]=opy[s][px+5][bx+5];
}
c[100]=c[100]+nx1;
y[100]=y[100]+nx2;
System.out.println(maxv);
}
int search(double u1){
double c1;
int n1;
n1=-999;
c1=0;
if(u1>-900)c1=Math.exp(u1);
if(u1>-900)n1=(int)(c1/h);
return n1;
}
double u(double c1,double x1){
double u1,c2,x2;
int pp;
pp=0;
c2=c1;
x2=x1;
if (c2<0)pp=100;
if (x2<0)pp=100;
if (x2>1)pp=100;
if (x2==0)pp=100;
if (pp>50)c2=0.5;
if (pp>50)x2=0.5;
u1=Math.log(c2)+Math.log(x2);
if (pp>50)u1=-999;
return u1;
}
}
package w;
class linear{
int s;
double th[]= new double[101];
double c[]= new double[101];
double y[]= new double[101];
double tl,tr,w1;
double c1,y1;
void makedata(){
tl=tls(th);
tr=trs(tl,th);
for (s=1;s<101;s++){
y1=th[s]*lx(s,tl,tr,th);
c1=tr+(1-tl)*y1;
c[s]=c1;
y[s]=y1;
}
}
double lx(int s,double tl,double tr,double th[]){
double w1,l1;
w1=(1-tl)*th[s];
l1=(w1-tr)/(2*+w1);
if (l1<0)l1=0;
return l1;
}
double bud(double tl,double tr,double th[]){
double c1,y1,b1;
int s;
b1=0;
for (s=1;s<101;s++){
y1=th[s]*lx(s,tl,tr,th);
c1=(1-tl)*y1+tr;
b1=b1+y1-c1;
}
return b1;
}
double trs(double tl,double th[]){
double tr1,tr2,tr3,b1,b2;
int t;
tr1=0.1;
tr2=0.2;
b1=bud(tl,tr1,th);
t=0;
while(t<100){
b2=bud(tl,tr2,th);
tr3=tr2-b2*(tr2-tr1)/(b2-b1);
tr1=tr2;
tr2=tr3;
b1=b2;
if (b2*b2<0.0001)t=1000;
t=t+1;
}
return tr2;
}
double tls(double th[]){
int m;
double tl,tr,w1,maxw,maxtl;
maxw=-999;
maxtl=0;
for (m=10;m<50;m++){
tl=0.01*m;
tr=trs(tl,th);
w1=wel(tl,tr,th);
if (w1>maxw)maxtl=tl;
if (w1>maxw)maxw=w1;
}
return maxtl;
}
double wel(double tl,double tr,double th[]){
double c1,l1,w1;
int s;
w1=0;
for (s=1;s<101;s++){
l1=lx(s,tl,tr,th);
c1=(1-tl)*th[s]*l1+tr;
w1=w1+u(c1,1-l1);;
}
return w1;
}
double u(double c1,double x1){
double u1,c2,x2;
int pp;
pp=0;
c2=c1;
x2=x1;
if (c2<0)pp=100;
if (x2<0)pp=100;
if (x2>1)pp=100;
if (x2==0)pp=100;
if (pp>50)c2=0.5;
if (pp>50)x2=0.5;
u1=Math.log(c2)+Math.log(x2);
if (pp>50)u1=-999;
return u1;
}
}
package w;
class nearlinear{
int s;
int th[]= new int[101];
double ths[]= new double[101];
double cs[]= new double[101];
double ys[]= new double[101];
int c[]= new int[101];
int y[]= new int[101];
double tl,tr,w1;
double c1,y1;
double h;
void makedata(){
for (s=1;s<101;s++){
ths[s]=th[s]*h;
}
linear sub=new linear();
sub.th=ths;
sub.makedata();
cs=sub.c;
ys=sub.y;
for (s=1;s<101;s++){
c[s]=(int)(cs[s]/h);
y[s]=(int)(ys[s]/h);
}
}
}
最終更新:2013年10月02日 12:03