public class tax84{
public static void main(String[] args) {
double th1[]=new double[11];
double th2[]=new double[11];
double y1[][]=new double[11][11];
double y2[][]=new double[11][11];
double c[][]=new double[11][11];
int s1,s2;
double l1,c1,l2,u1,u2,w1,w2,h,b2;
double tk,tl,tr,maxv,maxwel,maxtk,maxtl,maxtr,we;
double z,v1;
int opc[][][]=new int[11][11][1001];
int op1[][][]=new int[11][11][1001];
int op2[][][]=new int[11][11][1001];
int op[]=new int[11];
double cs[][][]=new double[11][11][1001];
double ys1[][][]=new double[11][11][1001];
double ys2[][][]=new double[11][11][1001];
int b[][]=new int[11][1001];
double v[][][]=new double[10][1001][11];
double endv[]=new double[1001];
int endn[]=new int[1001];
int goton[][][]=new int[11][1001][11];
int gotom[][][]=new int[11][1001][11];
int x;
int m,n,n1,n2,n3,b1,mx,nx;
int t1,t2,t3,j;
int ns;
for (s1=1;s1<11;s1++){
th1[s1]=0.2*s1;
}
for (s2=1;s2<11;s2++){
th2[s2]=0.1*s2;
}
maxwel=-999;
maxtk=0;
maxtl=0;
maxtr=0;
for (n1=5;n1<40;n1++){
for (n2=5;n2<40;n2++){
tk=0.01*n1;
tl=0.01*n2;
tr=trs(tk,tl,th1,th2);
we=wel(tk,tl,tr,th1,th2);;
if (we>maxwel)maxtk=tk;
if (we>maxwel)maxtl=tl;
if (we>maxwel)maxtr=tr;
if (we>maxwel)maxwel=we;
}
}
tk=maxtk;
tl=maxtl;
tr=maxtr;
for (s1=1;s1<11;s1++){
for (s2=1;s2<11;s2++){
l1=mlx(s1,s2,tk,tl,tr,th1,th2);
l2=flx(s1,s2,tk,tl,tr,th1,th2);
w1=(1-tk)*th1[s1];
w2=(1-tl)*th2[s2];
y1[s1][s2]=th1[s1]*l1;
y2[s1][s2]=th2[s2]*l2;
c[s1][s2]=w1*l1+w2*l2+tr;
}
}
h=0.001;
t3=0;
while(t3<100){
for (s1=1;s1<11;s1++){
for (n=1;n<1001;n++){
t1=0;
n1=0;
n2=0;
n3=0;
while(t1<100){
z=Math.random();
n1=0;
x=0;
if (z<0.3)x=-1;
if (z>0.7)x=1;
n1=x;
z=Math.random();
n2=0;
x=0;
if (z<0.3)x=-1;
if (z>0.7)x=1;
n2=x;
n3=0;
x=0;
z=Math.random();
if (z<0.3)x=-1;
if (z>0.7)x=1;
n3=x;
c1=c[s1][1]+n3*h;
l1=(y1[s1][1]+n1*h)/th1[s1];
l2=(y2[s1][1]+n2*h)/th2[1];
u1=ux(c1,l1,l2);
if (u1>-100)t1=1000;
opc[s1][1][n]=n3;
op1[s1][1][n]=n1;
op2[s1][1][n]=n2;
for (s2=2;s2<11;s2++){
t2=0;
while(t2<100){
z=Math.random();
n1=0;
x=0;
if (z<0.3)x=-1;
if (z>0.7)x=1;
n1=x;
n2=0;
x=0;
z=Math.random();
x=0;
if (z<0.3)x=-1;
if (z>0.7)x=1;
n2=x;
n3=0;
x=0;
z=Math.random();
if (z<0.3)x=-1;
if (z>0.7)x=1;
n3=x;
c1=c[s1][s2]+n3*h;
l1=(y1[s1][s2]+n1*h)/th1[s1];
l2=(y2[s1][s2]+n2*h)/th2[s2];
u1=ux(c1,l1,l2);
if (u1>-100)t2=1000;
n1=op1[s1][s2-1][n];
n2=op2[s1][s2-1][n];
n3=opc[s1][s2-1][n];
c1=c[s1][s2-1]+n3*h;
l1=(y1[s1][s2-1]+n1*h)/th1[s1];
l2=(y2[s1][s2-1]+n2*h)/th2[s2];
u2=ux(c1,l1,l2);
if (u2>u1)t2=0;
}
opc[s1][s2][n]=n3;
op1[s1][s2][n]=n1;
op2[s1][s2][n]=n2;
}
}
}
}
for (s1=1;s1<11;s1++){
for (s2=1;s2<11;s2++){
cs[s1][s2][0]=c[s1][s2];
ys1[s1][s2][0]=y1[s1][s2];
ys2[s1][s2][0]=y2[s1][s2];
}
}
for (s1=1;s1<11;s1++){
for (s2=1;s2<11;s2++){
for (n=1;n<1001;n++){
cs[s1][s2][n]=c[s1][s2]+opc[s1][s2][n]*h;
ys1[s1][s2][n]=y1[s1][s2]+op1[s1][s2][n]*h;
ys2[s1][s2][n]=y2[s1][s2]+op2[s1][s2][n]*h;
}
}
}
for (s1=1;s1<11;s1++){
b[s1][0]=0;
}
for (s1=1;s1<11;s1++){
for (n=1;n<1001;n++){
b1=0;
for (s2=1;s2<11;s2++){
b1=b1-opc[s1][s2][n];
b1=b1+op1[s1][s2][n];
b1=b1+op2[s1][s2][n];
}
b[s1][n]=b1;
}
}
s1=1;
for (n=0;n<1001;n++){
for (m=-5;m<6;m++){
v[s1][n][m+5]=-999;
}
}
m=0;
for (n=0;n<1001;n++){
v1=0;
for (s2=1;s2<11;s2++){
c1=cs[s1][s2][n];
l1=(ys1[s1][s2][n])/th1[s1];
l2=(ys2[s1][s2][n])/th2[s2];
u1=ux(c1,l1,l2);
v1=v1+u1;
}
m=b[s1][n];
z=0;
if (m>5)z=100;
if (m<-5)z=100;
if (z>50)m=0;
if (z>50)v1=-999;
v[s1][n][m+5]=v1;
}
ns=0;
for (s1=2;s1<10;s1++){
for (n=0;n<1001;n++){
for (m=-5;m<6;m++){
v1=0;
for (s2=1;s2<11;s2++){
c1=cs[s1][s2][n];
l1=(ys1[s1][s2][n])/th1[s1];
l2=(ys2[s1][s2][n])/th2[s2];
u1=ux(c1,l1,l2);
v1=v1+u1;
}
b1=b[s1][n];
mx=m-b1;
z=0;
if (mx>5)z=100;
if (mx<-5)z=100;
if (z>50)mx=0;
maxv=-999;
ns=0;
for (nx=0;nx<1001;nx++){
v1=v1+v[s1-1][nx][mx+5];
if (v1>maxv)ns=nx;
if (v1>maxv)maxv=v1;
}
if (z>50)maxv=-999;
v[s1][n][m+5]=maxv;
goton[s1][n][m+5]=ns;
gotom[s1][n][m+5]=mx;
}
}
}
s1=10;
for (n=0;n<1001;n++){
v1=0;
for (s2=1;s2<11;s2++){
c1=cs[s1][s2][n];
l1=(ys1[s1][s2][n])/th1[s1];
l2=(ys2[s1][s2][n])/th2[s2];
u1=ux(c1,l1,l2);
v1=v1+u1;
}
mx=-b[s1][n];
z=0;
if (mx>5)z=100;
if (mx<-5)z=100;
if (z>50)mx=0;
maxv=-999;
ns=0;
for (nx=0;nx<1001;nx++){
v1=v1+v[s1-1][nx][mx+5];
if (v1>maxv)ns=nx;
if (v1>maxv)maxv=v1;
}
if (z>50)maxv=-999;
endn[n]=ns;
endv[n]=maxv;
}
maxv=-999;
ns=0;
for (n=0;n<1001;n++){
if(endv[n]>maxv)ns=n;
if(endv[n]>maxv)maxv=endv[n];
}
System.out.println(maxv);
mx=-b[10][ns];
op[10]=ns;
op[9]=endn[op[10]];
for (j=1;j<9;j++){
s1=9-j;
op[s1]=goton[s1+1][op[s1+1]][mx+5];
mx=gotom[s1+1][op[s1+1]][mx+5];
}
for (s1=1;s1<11;s1++){
n=op[s1];
for (s2=1;s2<11;s2++){
c[s1][s2]=c[s1][s2]+opc[s1][s2][n]*h;
y1[s1][s2]=y1[s1][s2]+op1[s1][s2][n]*h;
y2[s1][s2]=y2[s1][s2]+op2[s1][s2][n]*h;
}
}
t3=t3+1;
}
}
static double bud(double tk,double tl,double tr,double th1[],double th2[]){
double b1,w1,w2,l1,l2,c1;
int s1,s2,i;
b1=0;
for (s1=1;s1<11;s1++){
for (s2=1;s2<11;s2++){
w1=(1-tk)*th1[s1];
w2=(1-tl)*th2[s2];
l1=1-(w1+w2+tr)/(3*w1);
l2=1-(w1+w2+tr)/(3*w2);
i=0;
if (l1<0)i=i+1;
if (l2>0)i=i+1;
if (i==2)l1=0;
if (i==2)l2=(w2-tr)/(2*w2);
i=0;
if (l1>0)i=i+1;
if (l2<0)i=i+1;
if (i==2)l1=(w1-tr)/(2*w1);
if (i==2)l2=0;
c1=w1*l1+w2*l2+tr;
b1=b1+th1[s1]*l1+th2[s2]*l2-c1;
}
}
return b1;
}
static double wel(double tk,double tl,double tr,double th1[],double th2[]){
double we,w1,w2,l1,l2,c1;
int s1,s2,i;
we=0;
for (s1=1;s1<11;s1++){
for (s2=1;s2<11;s2++){
w1=(1-tk)*th1[s1];
w2=(1-tl)*th2[s2];
l1=1-(w1+w2+tr)/(3*w1);
l2=1-(w1+w2+tr)/(3*w2);
i=0;
if (l1<0)i=i+1;
if (l2>0)i=i+1;
if (i==2)l1=0;
if (i==2)l2=(w2-tr)/(2*w2);
i=0;
if (l1>0)i=i+1;
if (l2<0)i=i+1;
if (i==2)l1=(w1-tr)/(2*w1);
if (i==2)l2=0;
c1=w1*l1+w2*l2+tr;
we=we+Math.log(c1)+Math.log(1-l1)+Math.log(1-l2);
}
}
return we;
}
static double trs(double tk,double tl,double[] th1,double[] th2){
double tr1,tr2,tr3,b1,b2;
int t1;
tr1=0.1;
tr2=0.05;
b1=bud(tk,tl,tr1,th1,th2);
t1=0;
while(t1<100){
b2=bud(tk,tl,tr2,th1,th2);
tr3=tr2-b2*(tr2-tr1)/(b2-b1);
b1=b2;
tr1=tr2;
tr2=tr3;
if (b2*b2<0.001)t1=1000;
t1=t1+1;
}
return tr2;
}
static double ux(double c1,double l1,double l2){
int pp;
double u1,cp1,lp1,lp2;
pp=0;
cp1=c1;
lp1=l1;
lp2=l2;
if (lp1<0)pp=100;
if (lp1>0.99)pp=100;
if (lp2<0)pp=100;
if (lp2>0.99)pp=100;
if (pp>50)lp1=0.5;
if (pp>50)lp2=0.5;
u1=Math.log(cp1)+Math.log(1-lp1)+Math.log(1-lp2);
if (pp>50)u1=-999;
return u1;
}
static double mlx(int s1,int s2,double tk,double tl,double tr,double[] th1,double th2[]){
int i;
double w1,w2,l1,l2;
w1=(1-tk)*th1[s1];
w2=(1-tl)*th2[s2];
l1=1-(w1+w2+tr)/(3*w1);
l2=1-(w1+w2+tr)/(3*w2);
i=0;
if (l1<0)i=i+1;
if (l2>0)i=i+1;
if (i==2)l1=0;
if (i==2)l2=(w2-tr)/(2*w2);
i=0;
if (l1>0)i=i+1;
if (l2<0)i=i+1;
if (i==2)l1=(w1-tr)/(2*w1);
if (i==2)l2=0;
return l1;
}
static double flx(int s1,int s2,double tk,double tl,double tr,double[] th1,double th2[]){
int i;
double w1,w2,l1,l2;
w1=(1-tk)*th1[s1];
w2=(1-tl)*th2[s2];
l1=1-(w1+w2+tr)/(3*w1);
l2=1-(w1+w2+tr)/(3*w2);
i=0;
if (l1<0)i=i+1;
if (l2>0)i=i+1;
if (i==2)l1=0;
if (i==2)l2=(w2-tr)/(2*w2);
i=0;
if (l1>0)i=i+1;
if (l2<0)i=i+1;
if (i==2)l1=(w1-tr)/(2*w1);
if (i==2)l2=0;
return l2;
}
}
最終更新:2010年05月24日 00:33