アットウィキロゴ

げい

public class tax112{
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];
double up[][][][][]=new double[11][11][3][3][3];
double wp[][][][][]=new double[11][10][3][3][3];
double zp[][][][][]=new double[10][11][3][3][3];
double sumu[][]=new double[11][101];
double sumv[][][]=new double[11][101][21];
int goton[][][]=new int[11][101][21];
int gotom[][][]=new int[11][101][21];
int endn[]=new int[101];
int endm[]=new int[101];
double endv[]=new double[101];
int sumb[][]=new int[11][101];
int opc[][][]=new int[11][11][101];
int op1[][][]=new int[11][11][101];
int op2[][][]=new int[11][11][101];
int op[]=new int[11];
int oq[]=new int[10];
int link[][][]=new int[11][101][101];
double tk,tl,tr;
double c1,w1,w2,l1,l2,u1,u2,v1,maxv;  
double we;
double maxwel,maxtk,maxtl,maxtr;
double h;
int m,n,n1,n2,n3,s1,s2,nx1,nx2,nx3,b1;
int t1,t2,t3,t4,t5;
int p1,p2,p3;
int j,ep;
int mx,nx,z,ns,nxs;
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;
t5=0;
while(t5<10){
for (s1=1;s1<11;s1++){
for (s2=1;s2<11;s2++){
for (n1=-1;n1<2;n1++){
for (n2=-1;n2<2;n2++){
for (n3=-1;n3<2;n3++){
c1=c[s1][s2]+n3*h;
l1=(y1[s1][s2]+n1*h)/th1[s1];
l2=(y2[s1][s2]+n2*h)/th2[s2];
up[s1][s2][n1+1][n2+1][n3+1]=ux(c1,l1,l2);
}
}
}
}
}

for (s1=1;s1<11;s1++){
for (s2=1;s2<10;s2++){
for (n1=-1;n1<2;n1++){
for (n2=-1;n2<2;n2++){
for (n3=-1;n3<2;n3++){
c1=c[s1][s2]+n3*h;
l1=(y1[s1][s2]+n1*h)/th1[s1];
l2=(y2[s1][s2]+n2*h)/th2[s2+1];
wp[s1][s2][n1+1][n2+1][n3+1]=ux(c1,l1,l2);
}
}
}
}
}

for (s1=1;s1<10;s1++){
for (s2=1;s2<11;s2++){
for (n1=-1;n1<2;n1++){
for (n2=-1;n2<2;n2++){
for (n3=-1;n3<2;n3++){
c1=c[s1][s2]+n3*h;
l1=(y1[s1][s2]+n1*h)/th1[s1+1];
l2=(y2[s1][s2]+n2*h)/th2[s2];
zp[s1][s2][n1+1][n2+1][n3+1]=ux(c1,l1,l2);
}
}
}
}
}

for (s1=1;s1<11;s1++){
for (n=1;n<101;n++){
t3=0;
while (t3<100){
t1=0;
n1=1;
n2=1;
n3=1;
while (t1<100){
n1=chance();
n2=chance();
n3=chance();
u1=up[s1][1][n1+1][n2+1][n3+1];
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;
n1=0;
n2=0;
n3=0;
while (t2<100){
n1=chance();
n2=chance();
n3=chance();
u1=up[s1][s2][n1+1][n2+1][n3+1];
j=0;
if (u1>-100)j=1000;
nx1=op1[s1][s2-1][n];
nx2=op2[s1][s2-1][n];
nx3=opc[s1][s2-1][n];
w1=wp[s1][s2-1][nx1+1][nx2+1][nx3+1];
if (w1>u1)j=0;;
if (j>100)t2=1000;
}
opc[s1][s2][n]=n3;
op1[s1][s2][n]=n1;
op2[s1][s2][n]=n2;
}
ep=0;
for (s2=1;s2<11;s2++){
ep=ep+op1[s1][s2][n]+op2[s1][s2][n]-opc[s1][s2][n];
}
j=0;
if (ep<11)j=j+1;
if (ep>-11)j=j+1;
if (j==2)t3=1000;
}
}
}

for (s1=1;s1<11;s1++){  
for (n=1;n<101;n++){
v1=0;
for (s2=1;s2<11;s2++){  
n1=op1[s1][s2][n];
n2=op2[s1][s2][n];
n3=opc[s1][s2][n];
u1=up[s1][s2][n1+1][n2+1][n3+1];
v1=v1+u1;
}
sumu[s1][n]=v1;
}
}

for (s1=1;s1<11;s1++){  
for (n=1;n<101;n++){
b1=0;
for (s2=1;s2<11;s2++){  
n1=op1[s1][s2][n];
n2=op2[s1][s2][n];
n3=opc[s1][s2][n];
b1=b1+n1+n2-n3;
}
sumb[s1][n]=b1;
}
}


for (s1=2;s1<11;s1++){
for (p1=1;p1<101;p1++){
for (p2=1;p2<101;p2++){
j=0;
for (s2=1;s2<11;s2++){
n3=opc[s1][s2][p1];
n1=op1[s1][s2][p1];
n2=op2[s1][s2][p1];
u1=up[s1][s2][n1+1][n2+1][n3+1];
n3=opc[s1-1][s2][p2];
n1=op1[s1-1][s2][p2];
n2=op2[s1-1][s2][p2];
u2=zp[s1-1][s2][n1+1][n2+1][n3+1];
if (u2>u1)j=100;
}
link[s1][p1][p2]=0;
if (j>50)link[s1][p1][p2]=100;
}
}
}


for (n=1;n<101;n++){
m=sumb[1][n];
sumv[1][n][m+10]=sumu[1][n];
}

for (s1=2;s1<10;s1++){
for (m=-10;m<11;m++){
for (n=1;n<101;n++){
u1=sumu[s1][n];
mx=m-sumb[s1][n];
z=0;
if (mx>10)z=100;
if (mx<-10)z=100;
if (z>50)mx=0;
maxv=-999;
nxs=1;
for (nx=1;nx<101;nx++){
v1=u1+sumv[s1-1][nx][mx+10];
if (link[s1][n][nx]>50)v1=-999;
if (v1>maxv)nxs=nx;
if (v1>maxv)maxv=v1;
}
if (z>50)maxv=-999;
goton[s1][n][m+10]=nxs;
gotom[s1][n][m+10]=mx;
sumv[s1][n][m+10]=maxv;
}
}
}

for (n=1;n<101;n++){
u1=sumu[10][n];
mx=-sumb[10][n];
maxv=-999;
nxs=1;
for (nx=1;nx<101;nx++){
v1=u1+sumv[9][nx][mx+10];
if (link[10][n][nx]>50)v1=-999;
if (v1>maxv)nxs=nx;
if (v1>maxv)maxv=v1;
}
endn[n]=nxs;
endm[n]=mx;
endv[n]=maxv;
}

maxv=-999;
ns=1;
for (n=1;n<101;n++){
if(endv[n]>maxv)ns=n;
if(endv[n]>maxv)maxv=endv[n];
}
op[10]=ns;
op[9]=endn[op[10]];
oq[9]=endm[op[10]];
for (j=1;j<9;j++){
s1=9-j;
op[s1]=goton[s1+1][op[s1+1]][oq[s1+1]+10];
oq[s1]=gotom[s1+1][op[s1+1]][oq[s1+1]+10];
}
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]=y1[s1][s2]+op2[s1][s2][n]*h;
}
}
System.out.println(maxv);
t5=t5+1;
}

}
static int chance(){
double x;
int xp;
x=Math.random();
xp=0;
if (x>0.7)xp=1;
if (x<0.7)xp=-1;
return xp;
}
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月26日 00:52